1 Meeting Notes:

After meeting with Josh Keller (Statistics, CSU), we decided to try to implement the modeling framework used by the MESA Air team (Keller et al., 2015). This was implemented using the SpatioTemporal package in R.

The original paper used PLS to select the spatial covariates. That will be the eventual approach for this analysis, but for now, I’m going to use the covariates selected by the LASSO model (see 16a_LUR_BC_average.R)

Update 03.18.20: I was receiving an error when trying to use the estimate.STmodel() function from the SpatioTemporal package. I emailed Josh Keller for advice, and he responded with some suggestions. I’ve pasted his email response at the end of this script for safe keeping

Basically, I’m going to start with the following:

  • Simple model (i.e., only one time trend)
  • iid covariance structure

Update 03.24.20: Sheryl and I met with Josh Keller again today to go over the preliminary version of the model and talk about next steps. Here are some of the take-aways from the meeting:

  • We should add the entirety of the BC monitoring data at the central site to help establish long-term time trends
  • We need to add degrees of freedom to the time trends. Josh recommended 4 per year (but we can also try 8, 12, etc.). Time trends will become more obvious with more data
  • I need to use the PM and NO2 monitoring data to establish temporal trends. These are different from the ST predictors! Start by plotting the time trends of PM, temp, and NO2. We might want to use PM for the temporal trends and NO2 and Temp as ST predictors (other combinations might work too, such as adding PM to the ST predictors). Don’t use BC as a ST predictor
    • When looking at the temporal trends, use createSTdata
    • Need to standardize PM and NO2
    • When ready to create the STdata object for model fitting, assign the temporal trend data set to the $trend slot of the STdata object
  • We also want to run a model without ST predictors as a comparison
  • Make the LUR function the same for the intercept and the time trends
  • Rather than set nugget = ~type, set nugget = T
  • Change from the iid covariance structure to the exp structure
  • Run a number of initial conditions to try to find the right minimum
    • For nuggets, set them to between -1 and -6
    • For ranges, set them to between 0 and 4
  • Cross validation!
    • For distributed sites, use 10-fold CV
    • For central site, use LOOCV
  • There is a trade-off for the number of basis functions selected. For now, I’m going to stick with one, and then we can see if more make sense later

Update 04.20.20: So far, it looks like I’ve been able to fit the model using the long-term PM data (scaled) for the temporal trends. There are still some outstanding things I need to work on:

  • [] Adding additional ST covariates (e.g., smoke days, temperature)
  • [] Using PLS to identify spatial covariates
  • [] Figure out how to predict to the full grid using the CV model

I’m going to stick with the LASSO-selected spatial predictors for now. In the future, I’ll be implementing PLS.

Update 04.24.20: Josh and I met to discuss some challenges with the model this far. These issues included:

  • User error! I never actually updated the time trend using the PM data– need to fix this bit of the code
  • for the PM STdata object, manually set the DF to 4 per year (i.e., set df = 12 rather than use dynamic code)
  • Log-transformation might not be necessary for this data set. The CV plots show a lot of outliers at the low end of the range. I need to look at histograms for each distribution (with and without transformation) to see
  • Campaign 4 might be an issue here. The time series of BC measurements show a lot of variability in BC. These crappy data might be influencing the model to the point where we cannot fit something well. We might need to drop Campaign 4 from the model. This might not be too big of an issue given that the model can account for time trends. I’m going to explore this now.

This version of the document contains the following changes:

  • I added the details about the data set from previous scripts
  • I dropped Campaign 4 data. The CV plot looks like this version of the model is performing better
  • I used both log-transformed BC and BC in the original units until I got to the CV step.
  • I was able to generate time trends using the PM and BC data, but I’m not sure they are an improvement

Update 05.05.20: Some updates in this version of the document based on my most recent conversation with Josh:

  • Sticking with the log-transformed BC measurements
  • Going to try NO2 to identify long-term temporal trends instead of PM2.5
  • Try an “intermediate” model without spatial smoothing in the spatial predictors but with spatial smoothing in the time trend (i.e., set cov.beta == c("iid") and cov.nu == "exp")

An important note to keep in mind is that even if dropping the spatial smoothing helps with these predictors, that might change once we shift to using PLS to select spatial covariates. The additional model used here will just help guide final model decisions.

Main take-aways from this version of the document:

  • It looks like the model with smoothing in the temporal trend but not the spatial predictors (i.e., Model 2) performed well
  • Not sure if Model 3 adds value. It’ll be helpful to get Josh’s and Sheryl’s thoughts
  • I think I can use the NO2 data to estimate the temporal trends, and it looks like it works best with 2 basis functions
  • I’m unclear about how to use these new temporal trends in the model. When trying to create the ST model object with the new trends, I got an error about subscripts being out of bounds. Do I need to add the NO2 and BC data to the bc_obs object in the denver.data2.2 object? This will need sussing out!

Some next steps include:

  • Fixing the issue described above to see if we can get a model that has longer-term data
  • PLS vs. LASSO for choosing spatial predictors

Update 05.12.20: Josh sent some advice about fitting the model with the time trends using the NO2 data. Here I’m creating a new version of bc_st_no2 that goes as far back as the temporal trends (i.e., goes back to 2009). At first it looked like we would need to use two temporal trends, so that’s how I fit the models. I also include a summary table of model diagnostics at the end.

Some additional updates:

  • Added another intermediate model that uses ans exp covariance structure for the beta0 field and the errors but iid for the beta1 field
  • Added the new basis functions (Models 2.X), but had some trouble fitting all the models (see below)
  • Tried using just one basis function (even though there was residual autocorrelation) just to have a comparison
  • Added models that used two ST predictors (smoke days as a binary variable and NO2 as a continuous variable). These models used the two basis functions

Overall, I’m not seeing much variability in the R2 or RSME values. However, there is some difference in whether all of the CV models converge, so perhaps that’s a differentiating criterion.

In my (mostly uninformed) opinion, Model 4.2 is looking pretty good to mode forward with. It uses spatial smoothing in the error term, has long-term trend data with two basis functions thanks to the NO2 and BC monitors, it includes both NO2 and smoke days as spatiotemporal predictors, all of the CV models converged, and the R2 value is above 0.8.

## Loading required package: Matrix

2 Exploring the LUR data set

2.1 The sampling framework

In total, we have 814 filters collected across 4 sampling campaigns. We collected data at 61 distributed sites and 169 EPA monitoring sites. Due to a variety of logtistical challenges, not all sites were available for all campaigns. The number of distributed site sampling locations for Campaigns 1, 2, 3, and 4 were 45, 52, 31, and 50, respectively.

Out goal was to obtain at least 6 weekly integrated samples at each location. The number of samples collected at each distriubted monitoring site varied from 2 to 20.

The campaigns roughly covered the early and late summer, fall, and winter seasons. We are lacking coverage during the spring season. Due to some interesting relationships between our co-located distributed site monitor data and the central BC monitor data during the winter, we are conducting a follow-up winter/spring campaign right now.

UPDATE: Due to logistical challenges associated with the COVID-19 pandemic, we were unable to complete our follow-up campaign.

campaign Start_Date End_Date
Campaign1 2018-05-08 2018-07-02
Campaign2 2018-07-10 2018-08-27
Campaign3 2018-10-09 2018-11-20
Campaign4 2019-01-22 2019-03-12

On average, weekly sampling periods lasted 4.94 days and ranged from 1.96 to 6.01. 90% of samples collected has runtimes exceeding 4.61 days.

## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

We also have daily PM2.5 data from 9 central site monitors, temperature data from 12, and NO2 data from 6 central site monitors in the 6-county Denver metro area.

###Table summarizing the number of weekly-integrated filter samples collected at each sampling location for each campaign

site_id Campaign1 Campaign2 Campaign3 Campaign4 total
1 5 6 3 6 20
2 6 5 NA 5 16
3 5 NA 4 3 12
4 5 6 NA 4 15
5 7 4 1 5 17
6 5 5 NA NA 10
7 7 4 3 6 20
8 4 6 NA 6 16
9 5 5 6 4 20
10 6 5 NA 4 15
11 7 5 5 3 20
12 4 5 NA 5 14
13 7 5 3 2 17
14 6 4 NA 6 16
15 7 5 4 4 20
16 6 6 NA 4 16
17 6 5 3 3 17
18 6 6 NA 4 16
19 7 4 3 2 16
20 6 NA NA 4 10
21 6 2 NA NA 8
22 6 6 NA NA 12
23 7 5 5 2 19
24 6 NA NA NA 6
25 7 5 2 3 17
26 6 4 NA 5 15
27 5 4 4 5 18
28 6 6 NA 6 18
29 5 4 2 5 16
30 6 6 NA 6 18
31 5 5 4 3 17
32 6 5 NA 4 15
33 5 3 5 4 17
34 6 6 NA 5 17
35 3 4 3 5 15
36 6 4 NA 4 14
37 5 4 3 4 16
38 6 3 NA 4 13
39 5 5 3 3 16
40 6 4 NA 4 14
41 6 6 NA 3 15
42 6 5 NA NA 11
43 6 6 NA 4 16
44 6 NA NA NA 6
45 6 5 NA 1 12
46 NA 5 4 3 12
47 NA 5 5 6 16
48 NA 1 4 3 8
49 NA 6 NA 3 9
50 NA 4 NA 1 5
51 NA 4 5 2 11
52 NA 5 4 5 14
53 NA 5 3 2 10
54 NA 5 4 5 14
55 NA 6 NA 2 8
56 NA 5 1 NA 6
57 NA NA 2 NA 2
58 NA NA 3 NA 3
59 NA NA 3 NA 3
60 NA NA 4 NA 4
61 NA NA NA 5 5

###Plot of when distributed site monitors were deployed

###Our sampling locations cover the entire Denver metro area within the 470 loop.

ggplot() +
  geom_sf(data = lur_data_sf, aes(color = "pt"), show.legend = "point") +
  geom_sf(data = highways, aes(color = "high"), show.legend = "line") +
  scale_color_manual(name = "Feature",
                     values = c("high" = "red", "pt" = "black"),
                     labels = c("high" = "Highways", "pt" = "Sites")) +
  simple_theme

2.3 Relationships between distributed site and central site BC

###Relationships between the distributed site BC and the central monitor are weak. The correlation coefficient for distributed site BC (time weighted average) to central site BC (averaged to the same sampling period for each filter) is NA

## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 23 rows containing non-finite values (stat_smooth).
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 23 rows containing non-finite values (stat_smooth).
## Warning: Removed 23 rows containing missing values (geom_point).

###The relationship looks different when we average all distributed sites (based on sampling start and end date). Here the data are averaged across all sites with the same start and end sampling date

## `geom_smooth()` using formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 3 rows containing non-finite values (stat_smooth).
## Warning: Removed 3 rows containing missing values (geom_point).

###Relationships between central site PM2.5 (averaged across all monitors in the area) and distributed site BC. Here PM2.5 is averaged for the same sampling start and end dates as the distributed site measurements. The correlation coefficient for distributed site BC (time weighted average) to central site PM2.5 (averaged to the same sampling period for each filter) is 0.2429175

## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

###Relationships between central site temperature (averaged across all monitors in the area) and distributed site BC. Here temperature is averaged for the same sampling start and end dates as the distributed site measurements. The correlation coefficient for distributed site BC (time weighted average) to central site temperature (averaged to the same sampling period for each filter) is -0.6628218

## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

###Relationships between central site NO2 (averaged across all monitors in the area) and distributed site BC. Here NO2 is averaged for the same sampling start and end dates as the distributed site measurements. The correlation coefficient for distributed site BC (time weighted average) to central site temperature (averaged to the same sampling period for each filter) is 0.4927855.

## `geom_smooth()` using formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

2.4 Charaterizing spatial and temporal variability

###What is the distribution of coefficient of variation (CV) values for each sampling location?

Across all distributed site filters, the CV for black carbon measurements is 41%

Some distributed sampling locations have a large amount of variability (CV > 0.25) in weekly BC concentrations measured across the study period compared to others.

## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

3 Data Decisions: Transformation? Include Campaign 4?

We need to decide if we want to use a log-transformation. We also need to decide if we want to include Campaign 4. As detailed above, there is something wonky about those data. We have a second “winter” campaign running now, but the UPAS aren’t co-located with the aethalometer, so it’s unclear if we can use those data to check to see if our original winter campaign was successful or not.

Update! John and Ben’s theory is that lower temps messed with our runtimes. We checked in with Scott Weichenthal (McGill) since he is also trying to use the UPAS as outdoor monitors. He noted that at cold temps the monitors just shut down, and that they needed to repeat a campaign because of that, so perhaps there’s some validity to that idea. The PM data may have been less affected given higher PM concentrations in the winter in general.

3.1 Comparing distributions for BC and log-transformed BC

3.1.1 BC from all campaigns with and without log-transformation

3.1.2 BC after dropping Campaign 4 (winter) with and without log-transformation

At this point, I’m going to drop Campaign 4 and move forward with trying to fit the model using the reduced data set. I’ll be using the log-transformed BC concentrations.

4 Formatting the data for the Spatiotemporal package

I need to get data into the correct format to be able to run the model. Here I am using the log-transformed concentrations and dropping the Campaign 4 data.

4.1 Issue with Site 61

For initial iterations of this model, Site 61 looked much different from the others, so I dropped it for now. I’ll need to go back and figure out what was wonky about that site later.

Update: Dropping Campaign 4 removed site 61, so no need to dig in unless we want to add those results back.

4.2 Observations of black carbon at the distributed and central sites.

Going to set up objects with log-transformed data and non-transformed BC data.

# With log transformation
bc_obs <- lur_data2 %>%
  select(site_id, sample_week, bc_ug_m3) %>%
  mutate(log_bc = log(bc_ug_m3)) %>%
  select(-bc_ug_m3) %>%
  pivot_wider(id_cols = sample_week,
              names_from = site_id, values_from = log_bc) %>%
              # names_from = site_id, values_from = bc_ug_m3) %>%
  as.data.frame() %>%
  arrange(sample_week)
rownames(bc_obs) <- bc_obs$sample_week
bc_obs$sample_week <- NULL
bc_obs <- as.matrix(bc_obs)

bc_weeks <- rownames(bc_obs)

# rownames(bc_obs)
# colnames(bc_obs)
class(bc_obs)
## [1] "matrix"
dim(bc_obs)
## [1] 169  61
# # Without log-transformation
# bc_obs.nt <- lur_data2 %>%
#   select(site_id, sample_week, bc_ug_m3) %>%
#   # mutate(log_bc = log(bc_ug_m3)) %>%
#   # select(-bc_ug_m3) %>%
#   pivot_wider(id_cols = sample_week,
#               # names_from = site_id, values_from = log_bc) %>%
#               names_from = site_id, values_from = bc_ug_m3) %>%
#   as.data.frame() %>%
#   arrange(sample_week)
# rownames(bc_obs.nt) <- bc_obs.nt$sample_week
# bc_obs.nt$sample_week <- NULL
# bc_obs.nt <- as.matrix(bc_obs.nt)
# 
# bc_weeks.nt <- rownames(bc_obs.nt)
# 
# # rownames(bc_obs)
# # colnames(bc_obs)
# class(bc_obs.nt)
# dim(bc_obs.nt)

4.3 Spatial covariates at the distributed site

These are based on the LASSO model (THIS WILL CHANGE IN THE FUTURE!! I just know how to use LASSO vs. PLS). Make sure the covariates are scaled here. Here I’m using the variables selected by the LASSO model using only three campaigns worth of data and a log-transformed outcome.

#' log-tranformed data
covars
##  [1] "impervious_2500"     "open_2500"           "low_int_100"        
##  [4] "med_int_50"          "high_int_50"         "high_int_100"       
##  [7] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [10] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [13] "aadt_2500"
bc_sp_cov <- select(lur_data2, site_id, lon, lat, all_of(covars)) %>%
  distinct() %>%
  mutate_at(.vars = vars(covars),
            scale)
## Note: Using an external vector in selections is ambiguous.
## i Use `all_of(covars)` instead of `covars` to silence this message.
## i See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
## This message is displayed once per session.
bc_sp_cov <- bc_sp_cov %>%
  rename(ID = site_id) %>%
  mutate(lon2 = lon, lat2 = lat) %>%
  st_as_sf(coords = c("lon2", "lat2"), crs = ll_wgs84) %>%
  st_transform(crs = albers)
sp_coords <- do.call(rbind, st_geometry(bc_sp_cov)) %>%
  as_tibble() %>% setNames(c("x","y"))
## Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if `.name_repair` is omitted as of tibble 2.0.0.
## Using compatibility `.name_repair`.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
bc_sp_cov <- bind_cols(bc_sp_cov, sp_coords) %>%
  st_set_geometry(NULL) %>%
  as.data.frame()

bc_sp_cov$type <- ifelse(bc_sp_cov$ID == "central", "central", "dist")
bc_sp_cov$type <- as.factor(bc_sp_cov$type)
# bc_sp_cov$type

# head(bc_sp_cov)
# class(bc_sp_cov)
cor(bc_sp_cov[,covars])
##                     impervious_2500   open_2500 low_int_100  med_int_50
## impervious_2500          1.00000000 -0.83510376  0.04147581 -0.16679293
## open_2500               -0.83510376  1.00000000 -0.12603064 -0.05636061
## low_int_100              0.04147581 -0.12603064  1.00000000 -0.12631919
## med_int_50              -0.16679293 -0.05636061 -0.12631919  1.00000000
## high_int_50              0.47483018 -0.41635316 -0.40185252  0.11602031
## high_int_100             0.52311084 -0.42248110 -0.42323883  0.11793239
## ag_250                  -0.27936743  0.21175032 -0.08010687 -0.01607492
## pop_den_50               0.38882480 -0.43039859  0.47294767  0.03873098
## dist_m_compost          -0.23740048  0.36015952 -0.11994547  0.24386038
## dist_m_military         -0.03254975  0.04081092  0.04177673 -0.27904653
## len_m_highways_2500      0.64494301 -0.49689181 -0.03038655 -0.07783019
## aadt_100                 0.42486549 -0.34876292 -0.28464438  0.03359576
## aadt_2500                0.46380170 -0.30096796 -0.07081120 -0.13990581
##                     high_int_50 high_int_100      ag_250  pop_den_50
## impervious_2500      0.47483018  0.523110836 -0.27936743  0.38882480
## open_2500           -0.41635316 -0.422481096  0.21175032 -0.43039859
## low_int_100         -0.40185252 -0.423238827 -0.08010687  0.47294767
## med_int_50           0.11602031  0.117932388 -0.01607492  0.03873098
## high_int_50          1.00000000  0.897420410 -0.06773259 -0.03835657
## high_int_100         0.89742041  1.000000000 -0.11729969 -0.05518337
## ag_250              -0.06773259 -0.117299694  1.00000000 -0.25195719
## pop_den_50          -0.03835657 -0.055183373 -0.25195719  1.00000000
## dist_m_compost      -0.10560558 -0.103918047  0.17279043 -0.12463877
## dist_m_military      0.02312569  0.005546725 -0.07173031 -0.06287839
## len_m_highways_2500  0.27706123  0.341931815 -0.24170133  0.03982997
## aadt_100             0.62883088  0.784232910 -0.10573403 -0.09971011
## aadt_2500            0.18533105  0.271784649 -0.11425336 -0.06750291
##                     dist_m_compost dist_m_military len_m_highways_2500
## impervious_2500        -0.23740048    -0.032549751         0.644943011
## open_2500               0.36015952     0.040810919        -0.496891814
## low_int_100            -0.11994547     0.041776735        -0.030386550
## med_int_50              0.24386038    -0.279046527        -0.077830187
## high_int_50            -0.10560558     0.023125694         0.277061226
## high_int_100           -0.10391805     0.005546725         0.341931815
## ag_250                  0.17279043    -0.071730306        -0.241701329
## pop_den_50             -0.12463877    -0.062878388         0.039829971
## dist_m_compost          1.00000000    -0.738189101        -0.086198948
## dist_m_military        -0.73818910     1.000000000        -0.008127746
## len_m_highways_2500    -0.08619895    -0.008127746         1.000000000
## aadt_100               -0.13357005     0.131174981         0.433081107
## aadt_2500               0.03881186    -0.225380937         0.475034135
##                        aadt_100   aadt_2500
## impervious_2500      0.42486549  0.46380170
## open_2500           -0.34876292 -0.30096796
## low_int_100         -0.28464438 -0.07081120
## med_int_50           0.03359576 -0.13990581
## high_int_50          0.62883088  0.18533105
## high_int_100         0.78423291  0.27178465
## ag_250              -0.10573403 -0.11425336
## pop_den_50          -0.09971011 -0.06750291
## dist_m_compost      -0.13357005  0.03881186
## dist_m_military      0.13117498 -0.22538094
## len_m_highways_2500  0.43308111  0.47503413
## aadt_100             1.00000000  0.21952160
## aadt_2500            0.21952160  1.00000000
#' Untransformed data
# covars.nt
# bc_sp_cov.nt <- select(lur_data2, site_id, lon, lat, covars.nt) %>%
#   distinct() %>%
#   mutate_at(.vars = vars(covars.nt),
#             scale)
# 
# bc_sp_cov.nt <- bc_sp_cov.nt %>%
#   rename(ID = site_id) %>%
#   mutate(lon2 = lon, lat2 = lat) %>%
#   st_as_sf(coords = c("lon2", "lat2"), crs = ll_wgs84) %>%
#   st_transform(crs = albers)
# sp_coords.nt <- do.call(rbind, st_geometry(bc_sp_cov.nt)) %>%
#   as_tibble() %>% setNames(c("x","y"))
# bc_sp_cov.nt <- bind_cols(bc_sp_cov.nt, sp_coords.nt) %>%
#   st_set_geometry(NULL) %>%
#   as.data.frame()
# 
# bc_sp_cov.nt$type <- ifelse(bc_sp_cov.nt$ID == "central", "central", "dist")
# bc_sp_cov.nt$type <- as.factor(bc_sp_cov.nt$type)
# 
# # head(bc_sp_cov.nt)
# # class(bc_sp_cov.nt)
# cor(bc_sp_cov.nt[,c(4:17)])

4.4 Spatiotemporal covariates at the distributed sites

We have available IDW estimates of temp, NO2, PM2.5, and BC. For now, just using NO2, since the correlations with distributed site log(BC) are decent. I originally tried to use two ST predictors, but ran into issues trying to fit the model.

#' log-transformed data
cor(log(lur_data2$bc_ug_m3), lur_data2$idw_no2, use = "complete")
## [1] 0.7363502
cor(log(lur_data2$bc_ug_m3), lur_data2$idw_pm, use = "complete")
## [1] 0.2050673
cor(log(lur_data2$bc_ug_m3), lur_data2$idw_temp, use = "complete")
## [1] -0.508503
#' Original units
# cor(lur_data2$bc_ug_m3, lur_data2$idw_no2, use = "complete")
# cor(lur_data2$bc_ug_m3, lur_data2$idw_pm, use = "complete")
# cor(lur_data2$bc_ug_m3, lur_data2$idw_temp, use = "complete")

4.5 Create the ST data object and determine the number of basis functions for the temporal trend

For now, going to use one ST predictor (NO2 estimated for each sampling location). Josh advised 4 degrees of freedom per year.

Based on the plots below, it looks like we can still reasonably use one basis function for now, but I might try two in the future since that’s where the metrics seem to level off. There might be some advantage to using more than 4 df per year. I’ll need to ask Josh if these results suggest we need to add df to the basis functions (over the 4/year he originally suggested as a starting point).

# With log-transformation
denver.data <- createSTdata(obs = bc_obs,
                            covars = bc_sp_cov,
                            SpatioTemporal = list(bc_st_no2 = bc_st_no2))
D <- createDataMatrix(denver.data)
# names(denver.data)
# print(denver.data)

# Determine the number of basis functions
n_years <- length(unique(as.Date(cut(as.Date(rownames(bc_obs)), "year"))))

SVD.cv.4py <- SVDsmoothCV(D, 0:4, df = 4*n_years)
print(SVD.cv.4py)
## Result of SVDsmoothCV, average of CV-statistics:
##                  MSE        R2       AIC       BIC
## n.basis.0 0.03571227 0.0000000 -124.9290 -123.9459
## n.basis.1 0.01988745 0.5089338 -139.4642 -137.4864
## n.basis.2 0.01661506 0.6023673 -146.9044 -143.8939
## n.basis.3 0.01467326 0.6575138 -152.6545 -148.5734
## n.basis.4 0.01410287 0.6793547 -153.6368 -148.4893
plot(SVD.cv.4py)

n_df <- 4
n_basis <- 1

# Add the smooth temporal basis functions to the ST data object
denver.data <- updateTrend(denver.data, n.basis = n_basis, df = n_df*n_years)
## Replacing existing trend.
head(denver.data$trend)
plot(denver.data$trend$date, denver.data$trend$V1, col = 1, pch = 16, cex = 0.5,
     xlab = "Date", ylab = "BC",
     main = "Basis function (with log-transformation)")
lines(denver.data$trend$date, denver.data$trend$V1, col = 2)

layout(matrix(c(1,2,1,3), 2, 2))

par(mar=c(2.3,3.3,2,1), mgp=c(2,1,0))
plot(denver.data, "loc", main="Occurrence of Observations", xlab="",
     ylab="Location", col=c("black", "red"), legend.loc=NULL)
par(mar=c(3.3,3.3,2,1))
qqnorm(denver.data, line=1)
scatterPlot(denver.data, covar="aadt_100", xlab="AADT in a 100 m buffer",
            ylab="BC (log ug/m3)", pch=19, cex=.25,
            smooth.args=list(span=4/5,degree=2))

4.6 Evaluate the basis functions

Plotting the temporal trends at a few of the sites (using the log-transformed data)

par(mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
layout(matrix(c(1,1,2,2,3,4), 3, 2, byrow=TRUE))
plot(denver.data, "obs", ID="d_1", xlab="", ylab="BC (log ug/m3)",
     main="Temporal trend d_1")
plot(denver.data, "res", ID="d_1", xlab="", ylab="BC (log ug/m3)")
plot(denver.data, "acf", ID="d_1")
plot(denver.data, "pacf", ID="d_1")

par(mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
layout(matrix(c(1,1,2,2,3,4), 3, 2, byrow=TRUE))
plot(denver.data, "obs", ID="d_20", xlab="", ylab="BC (log ug/m3)",
     main="Temporal trend d_20")
plot(denver.data, "res", ID="d_20", xlab="", ylab="BC (log ug/m3)")
plot(denver.data, "acf", ID="d_20")
plot(denver.data, "pacf", ID="d_20")

par(mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
layout(matrix(c(1,1,2,2,3,4), 3, 2, byrow=TRUE))
plot(denver.data, "obs", ID="d_53", xlab="", ylab="BC (log ug/m3)",
     main="Temporal trend d_53")
plot(denver.data, "res", ID="d_53", xlab="", ylab="BC (log ug/m3)")
plot(denver.data, "acf", ID="d_53")
plot(denver.data, "pacf", ID="d_53")

par(mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
layout(matrix(c(1,1,2,2,3,4), 3, 2, byrow=TRUE))
plot(denver.data, "obs", ID="central", xlab="", ylab="BC (log ug/m3)",
     main="Temporal trend central")
plot(denver.data, "res", ID="central", xlab="", ylab="BC (log ug/m3)")
plot(denver.data, "acf", ID="central")
plot(denver.data, "pacf", ID="central")

7 Updated models (NO2 + BC, two basis functions)

These modes are based on the expanded time trend data, and here we are using 2 temporal basis functions

7.1 Model 2.1: simplest form

7.1.1 Create the model object

For this version of the model, use iid for both cov.beta (beta0, beta1, beta2) and cov.nu (error term). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data2.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR2.1 <- list(covar_fun, covar_fun, covar_fun)

cov.beta2.1 <-  list(covf="iid", nugget = T)
cov.nu2.1 <- list(covf="iid", nugget = T, random.effect = FALSE)
locations2.1 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.2.1 <- createSTmodel(denver.data2.2, LUR = LUR2.1,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta2.1, cov.nu = cov.nu2.1,
                                  locations = locations2.1)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.2.1
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, iid, iid 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: iid 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

7.1.2 Estimate model parameters

We want to try a number of initial conditions to make sure we find the “right” solution.

names <- loglikeSTnames(denver.model.2.1, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.nugget.V1.iid"            
## [3] "log.nugget.V2.iid"             "nu.log.nugget.(Intercept).iid"
# x.init.2.1 <- cbind(c(rep(-1, 4)), c(rep(-2, 4)), c(rep(-3, 4)),
#                     c(rep(-4, 4)), c(rep(-5, 4)), c(rep(-6, 4)))
# x.init.2.1[nrow(x.init.2.1),] <- 0

x.init.2.1 <- cbind(c(0, 0, 0),
                    c(-5, -5, -5, -5),
                    c(-8, -5, -5, -5),
                    c(-8, -8, -5, -5),
                    c(-8, -8, -8, -8))
## Warning in cbind(c(0, 0, 0), c(-5, -5, -5, -5), c(-8, -5, -5, -5), c(-8, :
## number of rows of result is not a multiple of vector length (arg 1)
rownames(x.init.2.1) <- loglikeSTnames(denver.model.2.1, all=FALSE)
x.init.2.1
##                               [,1] [,2] [,3] [,4] [,5]
## log.nugget.const.iid             0   -5   -8   -8   -8
## log.nugget.V1.iid                0   -5   -5   -8   -8
## log.nugget.V2.iid                0   -5   -5   -5   -8
## nu.log.nugget.(Intercept).iid    0   -5   -5   -5   -8
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.2.1 <- estimate.STmodel(denver.model.2.1, x.init.2.1)
## Optimisation using starting value 1/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       141.33  |proj g|=           15
## At iterate    10  f =      -1314.1  |proj g|=        2.8341
## At iterate    20  f =      -1314.4  |proj g|=      0.080585
## At iterate    30  f =      -1314.4  |proj g|=    0.00038173
## 
## iterations 30
## function evaluations 38
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.000381727
## final function value -1314.42
## 
## F = -1314.42
## final  value -1314.419641 
## converged
## Optimisation using starting value 2/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1195.5  |proj g|=           20
## At iterate    10  f =      -1313.8  |proj g|=        1.7267
## At iterate    20  f =      -1314.4  |proj g|=       0.31734
## 
## iterations 23
## function evaluations 46
## segments explored during Cauchy searches 26
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0509106
## final function value -1314.38
## 
## F = -1314.38
## l(0) > u(0).  No feasible solutionfinal  value -1314.382110 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1219.5  |proj g|=           20
## At iterate    10  f =      -1313.5  |proj g|=         2.744
## At iterate    20  f =      -1314.4  |proj g|=       0.33297
## At iterate    30  f =      -1314.4  |proj g|=       0.16732
## 
## iterations 38
## function evaluations 50
## segments explored during Cauchy searches 40
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.184263
## final function value -1314.42
## 
## F = -1314.42
## final  value -1314.419688 
## converged
## Optimisation using starting value 4/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1233.8  |proj g|=           20
## At iterate    10  f =      -1313.3  |proj g|=        2.1302
## At iterate    20  f =      -1314.4  |proj g|=       0.33025
## 
## iterations 28
## function evaluations 46
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.108806
## final function value -1314.42
## 
## F = -1314.42
## l(0) > u(0).  No feasible solutionfinal  value -1314.419658 
## converged
## Optimisation using starting value 5/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       9044.4  |proj g|=           23
## At iterate    10  f =      -1312.9  |proj g|=        5.6592
## At iterate    20  f =      -1314.4  |proj g|=        0.0556
## 
## iterations 27
## function evaluations 50
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.000793915
## final function value -1314.42
## 
## F = -1314.42
## final  value -1314.419642 
## converged
print(est.denver.model.2.1)
## Optimisation for STmodel with 5 starting points.
##   Results: 4 converged, 1 not converged, 0 failed.
##   Best result for starting point 3, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]            [,2]           [,3]
## gamma.bc_st_no2                   0.0168242477   0.01678346061   0.0168235678
## alpha.const.(Intercept)          -0.0048559822  -0.00407697359  -0.0048413027
## alpha.const.impervious_2500       0.0511348885   0.05032484526   0.0511265284
## alpha.const.open_2500             0.0164488952   0.01566311568   0.0164408220
## alpha.const.low_int_100           0.0076555423   0.00703648939   0.0076502515
## alpha.const.med_int_50            0.0067269317   0.00690264183   0.0067288806
## alpha.const.high_int_50           0.0169354880   0.01688334496   0.0169357613
## alpha.const.high_int_100         -0.0227620778  -0.02275742619  -0.0227627634
## alpha.const.ag_250               -0.0041563842  -0.00416355430  -0.0041571132
## alpha.const.pop_den_50            0.0055546431   0.00560981860   0.0055545453
## alpha.const.dist_m_compost        0.0055763303   0.00560352565   0.0055761640
## alpha.const.dist_m_military       0.0186078382   0.01874655922   0.0186074358
## alpha.const.len_m_highways_2500  -0.0001726502  -0.00001912179  -0.0001717238
## alpha.const.aadt_100              0.0356804314   0.03544213418   0.0356792073
## alpha.const.aadt_2500            -0.0001759514   0.00001894612  -0.0001743325
## alpha.V1.(Intercept)             -0.2829121058  -0.28325784660  -0.2829159297
## alpha.V1.impervious_2500         -0.0546029902  -0.05514644030  -0.0546051023
## alpha.V1.open_2500               -0.0431021087  -0.04351573427  -0.0431083113
## alpha.V1.low_int_100             -0.0007644143  -0.00099452946  -0.0007670769
## alpha.V1.med_int_50              -0.0062925634  -0.00651173469  -0.0062948057
## alpha.V1.high_int_50              0.0133040470   0.01309567296   0.0133053110
## alpha.V1.high_int_100            -0.0402853206  -0.04022537869  -0.0402922677
## alpha.V1.ag_250                  -0.0112999114  -0.01179020390  -0.0113101017
## alpha.V1.pop_den_50              -0.0164807188  -0.01628277306  -0.0164817733
## alpha.V1.dist_m_compost          -0.0274040720  -0.02780484834  -0.0274124381
## alpha.V1.dist_m_military         -0.0138511539  -0.01410066125  -0.0138562204
## alpha.V1.len_m_highways_2500      0.0060508547   0.00609234818   0.0060473917
## alpha.V1.aadt_100                 0.0211500980   0.02015634787   0.0211458534
## alpha.V1.aadt_2500                0.0061797891   0.00598919947   0.0061771052
## alpha.V2.(Intercept)             -0.1851994283  -0.18557088016  -0.1851982373
## alpha.V2.impervious_2500         -0.0126973054  -0.01444927913  -0.0127057372
## alpha.V2.open_2500                0.0100065310   0.00864591479   0.0099942793
## alpha.V2.low_int_100              0.0013424270   0.00042789371   0.0013339134
## alpha.V2.med_int_50              -0.0016340637  -0.00179769782  -0.0016334567
## alpha.V2.high_int_50             -0.0039125896  -0.00442938594  -0.0039071982
## alpha.V2.high_int_100            -0.0450929992  -0.04454587725  -0.0451077423
## alpha.V2.ag_250                  -0.0304383660  -0.03089597365  -0.0304491777
## alpha.V2.pop_den_50              -0.0005178808  -0.00025760765  -0.0005177523
## alpha.V2.dist_m_compost           0.0052327198   0.00495055247   0.0052239931
## alpha.V2.dist_m_military          0.0117525963   0.01170776174   0.0117467172
## alpha.V2.len_m_highways_2500      0.0127751742   0.01310466368   0.0127722740
## alpha.V2.aadt_100                 0.0107787582   0.00924441966   0.0107775440
## alpha.V2.aadt_2500               -0.0036600477  -0.00363743149  -0.0036596382
## log.nugget.const.iid            -15.0000000000 -15.00000000000 -15.0000000000
## log.nugget.V1.iid                -8.8514490152 -11.73640691266  -8.8578864862
## log.nugget.V2.iid                -7.3053102690  -7.01025785875  -7.3046822548
## nu.log.nugget.(Intercept).iid    -4.4440430548  -4.44188853896  -4.4435089756
##                                           [,4]           [,5]
## gamma.bc_st_no2                   0.0168249272   0.0168242450
## alpha.const.(Intercept)          -0.0048692005  -0.0048559187
## alpha.const.impervious_2500       0.0511476857   0.0511348706
## alpha.const.open_2500             0.0164613791   0.0164488783
## alpha.const.low_int_100           0.0076650558   0.0076555359
## alpha.const.med_int_50            0.0067244082   0.0067269375
## alpha.const.high_int_50           0.0169359567   0.0169354917
## alpha.const.high_int_100         -0.0227617744  -0.0227620819
## alpha.const.ag_250               -0.0041559686  -0.0041563882
## alpha.const.pop_den_50            0.0055538262   0.0055546395
## alpha.const.dist_m_compost        0.0055760450   0.0055763281
## alpha.const.dist_m_military       0.0186060766   0.0186078290
## alpha.const.len_m_highways_2500  -0.0001748213  -0.0001726509
## alpha.const.aadt_100              0.0356838598   0.0356804341
## alpha.const.aadt_2500            -0.0001789704  -0.0001759498
## alpha.V1.(Intercept)             -0.2829065274  -0.2829121149
## alpha.V1.impervious_2500         -0.0545931986  -0.0546029720
## alpha.V1.open_2500               -0.0430936239  -0.0431021255
## alpha.V1.low_int_100             -0.0007607649  -0.0007644214
## alpha.V1.med_int_50              -0.0062883395  -0.0062925654
## alpha.V1.high_int_50              0.0133072439   0.0133040675
## alpha.V1.high_int_100            -0.0402862423  -0.0402853755
## alpha.V1.ag_250                  -0.0112906472  -0.0112999553
## alpha.V1.pop_den_50              -0.0164832921  -0.0164807356
## alpha.V1.dist_m_compost          -0.0273961874  -0.0274041071
## alpha.V1.dist_m_military         -0.0138461078  -0.0138511742
## alpha.V1.len_m_highways_2500      0.0060507191   0.0060508284
## alpha.V1.aadt_100                 0.0211660009   0.0211501215
## alpha.V1.aadt_2500                0.0061831563   0.0061797808
## alpha.V2.(Intercept)             -0.1851943077  -0.1851994017
## alpha.V2.impervious_2500         -0.0126689930  -0.0126972700
## alpha.V2.open_2500                0.0100296510   0.0100065199
## alpha.V2.low_int_100              0.0013564460   0.0013424123
## alpha.V2.med_int_50              -0.0016305567  -0.0016340471
## alpha.V2.high_int_50             -0.0039057338  -0.0039125256
## alpha.V2.high_int_100            -0.0450998082  -0.0450931327
## alpha.V2.ag_250                  -0.0304293017  -0.0304384152
## alpha.V2.pop_den_50              -0.0005216469  -0.0005178929
## alpha.V2.dist_m_compost           0.0052390458   0.0052326766
## alpha.V2.dist_m_military          0.0117550891   0.0117525611
## alpha.V2.len_m_highways_2500      0.0127707476   0.0127751372
## alpha.V2.aadt_100                 0.0108019471   0.0107788296
## alpha.V2.aadt_2500               -0.0036601841  -0.0036600452
## log.nugget.const.iid            -15.0000000000 -15.0000000000
## log.nugget.V1.iid                -8.8363177157  -8.8514475196
## log.nugget.V2.iid                -7.3099270086  -7.3053251488
## nu.log.nugget.(Intercept).iid    -4.4437816228  -4.4440417314
## 
## Function value(s):
## [1] 1314.420 1314.382 1314.420 1314.420 1314.420

7.1.3 Cross-validation

Define the CV groups (and don’t forget to set the seed here!)

set.seed(123)

unique(colnames(bc_obs2))
##  [1] "d_2"     "d_4"     "d_6"     "d_8"     "d_16"    "d_18"    "d_20"   
##  [8] "d_12"    "d_14"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_15"    "d_17"    "d_19"    "d_11"    "d_13"    "d_21"    "d_23"   
## [22] "d_25"    "d_28"    "d_30"    "d_32"    "d_40"    "d_41"    "d_42"   
## [29] "d_10"    "d_34"    "d_36"    "d_38"    "d_43"    "d_44"    "d_45"   
## [36] "d_3"     "d_1"     "d_27"    "d_29"    "d_31"    "d_39"    "d_9"    
## [43] "d_33"    "d_35"    "d_37"    "d_49"    "d_51"    "d_55"    "d_52"   
## [50] "d_56"    "d_50"    "d_54"    "d_46"    "d_47"    "d_53"    "d_48"   
## [57] "d_58"    "d_59"    "d_60"    "d_57"    "central"
Ind.cv.2.1 <- createCV(denver.model.2.1, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.2.1 <- sapply(split(denver.model.2.1$obs$ID, Ind.cv.2.1), unique)
print(sapply(ID.cv.2.1, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.2.1)
## Ind.cv.2.1
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.2.1 <- apply(sapply(ID.cv.2.1,function(x) denver.model.2.1$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.2.1) <- denver.model.2.1$locations$ID
print(I.col.2.1)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.2.1$locations$long,
     denver.model.2.1$locations$lat,
     pch=23+floor(I.col.2.1/max(I.col.2.1)+.5), bg=I.col.2.1,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.2.1.cv <- coef(est.denver.model.2.1, pars="cov")[,c("par","init")]
x.init.2.1.cv

Run the model with cross validation.

est.denver.2.1.cv <- estimateCV(denver.model.2.1, x.init.2.1.cv, Ind.cv.2.1)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1194.7  |proj g|=        8.126
## At iterate    10  f =        -1195  |proj g|=        2.4598
## At iterate    20  f =      -1195.2  |proj g|=       0.15305
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1195.177927 
## stopped after 24 iterations
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1100.6  |proj g|=           20
## At iterate    10  f =        -1194  |proj g|=        2.0587
## At iterate    20  f =      -1195.2  |proj g|=       0.69892
## 
## iterations 24
## function evaluations 36
## segments explored during Cauchy searches 26
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0283207
## final function value -1195.17
## 
## F = -1195.17
## final  value -1195.170892 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1203.1  |proj g|=       7.2538
## At iterate    10  f =      -1203.2  |proj g|=       0.59253
## At iterate    20  f =      -1203.3  |proj g|=      0.023264
## 
## iterations 22
## function evaluations 44
## segments explored during Cauchy searches 22
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00519591
## final function value -1203.32
## 
## F = -1203.32
## l(0) > u(0).  No feasible solutionfinal  value -1203.321348 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1110.3  |proj g|=           20
## At iterate    10  f =      -1202.3  |proj g|=        2.2789
## At iterate    20  f =      -1203.3  |proj g|=       0.72235
## At iterate    30  f =      -1203.3  |proj g|=        0.1883
## 
## iterations 38
## function evaluations 44
## segments explored during Cauchy searches 40
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0107955
## final function value -1203.32
## 
## F = -1203.32
## final  value -1203.321339 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1210.8  |proj g|=       5.4423
## At iterate    10  f =      -1211.7  |proj g|=       0.72644
## At iterate    20  f =      -1211.8  |proj g|=        2.2064
## 
## iterations 29
## function evaluations 33
## segments explored during Cauchy searches 29
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 1.64289e-05
## final function value -1211.81
## 
## F = -1211.81
## final  value -1211.812833 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1112.1  |proj g|=           20
## At iterate    10  f =      -1211.1  |proj g|=       0.54324
## 
## iterations 18
## function evaluations 31
## segments explored during Cauchy searches 20
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 0
## norm of the final projected gradient 0.0600187
## final function value -1211.48
## 
## F = -1211.48
## final  value -1211.484875 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1175.7  |proj g|=       11.026
## At iterate    10  f =      -1175.9  |proj g|=       0.12448
## At iterate    20  f =        -1176  |proj g|=       0.67916
## At iterate    30  f =      -1176.1  |proj g|=      0.092315
## 
## iterations 38
## function evaluations 47
## segments explored during Cauchy searches 38
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 6.83008e-06
## final function value -1176.13
## 
## F = -1176.13
## final  value -1176.129454 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1081.4  |proj g|=           20
## At iterate    10  f =      -1175.1  |proj g|=        2.1645
## At iterate    20  f =      -1175.9  |proj g|=       0.87289
## At iterate    30  f =        -1176  |proj g|=       0.63482
## At iterate    40  f =      -1176.1  |proj g|=       0.08808
## 
## iterations 45
## function evaluations 55
## segments explored during Cauchy searches 47
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 6.99856e-05
## final function value -1176.13
## 
## F = -1176.13
## final  value -1176.129454 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=        -1193  |proj g|=       9.6743
## At iterate    10  f =      -1194.4  |proj g|=       0.56968
## 
## iterations 18
## function evaluations 33
## segments explored during Cauchy searches 18
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00579242
## final function value -1194.46
## 
## F = -1194.46
## final  value -1194.461424 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1092.2  |proj g|=           20
## At iterate    10  f =      -1193.7  |proj g|=          1.27
## At iterate    20  f =      -1194.4  |proj g|=        1.0463
## 
## iterations 29
## function evaluations 40
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0664129
## final function value -1194.46
## 
## F = -1194.46
## final  value -1194.459308 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=        -1218  |proj g|=        8.722
## 
## iterations 9
## function evaluations 12
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0169696
## final function value -1218.15
## 
## F = -1218.15
## final  value -1218.152104 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1122.4  |proj g|=           20
## At iterate    10  f =      -1217.2  |proj g|=        2.2932
## At iterate    20  f =      -1218.1  |proj g|=       0.53565
## At iterate    30  f =      -1218.1  |proj g|=       0.50253
## 
## iterations 35
## function evaluations 56
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0848173
## final function value -1218.15
## 
## F = -1218.15
## l(0) > u(0).  No feasible solutionfinal  value -1218.154171 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1210.8  |proj g|=        7.969
## At iterate    10  f =      -1211.8  |proj g|=        1.2782
## 
## iterations 17
## function evaluations 24
## segments explored during Cauchy searches 17
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00762893
## final function value -1212.16
## 
## F = -1212.16
## final  value -1212.158119 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1112.1  |proj g|=           20
## At iterate    10  f =      -1210.9  |proj g|=        3.1999
## At iterate    20  f =      -1212.1  |proj g|=       0.34391
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 25
## function evaluations 61
## segments explored during Cauchy searches 28
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0315407
## final function value -1212.15
## 
## F = -1212.15
## final  value -1212.153404 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1199.7  |proj g|=       9.4254
## At iterate    10  f =      -1199.9  |proj g|=       0.39783
## At iterate    20  f =        -1200  |proj g|=     0.0016056
## 
## iterations 21
## function evaluations 32
## segments explored during Cauchy searches 21
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00160268
## final function value -1200.05
## 
## F = -1200.05
## final  value -1200.046977 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1105.6  |proj g|=           20
## At iterate    10  f =      -1199.1  |proj g|=        4.1519
## At iterate    20  f =        -1200  |proj g|=      0.039414
## 
## iterations 28
## function evaluations 36
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000118269
## final function value -1200.05
## 
## F = -1200.05
## final  value -1200.046976 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1206.6  |proj g|=       11.993
## At iterate    10  f =      -1206.8  |proj g|=      0.019608
## At iterate    20  f =      -1206.8  |proj g|=      0.035375
## 
## iterations 23
## function evaluations 32
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00231389
## final function value -1206.79
## 
## F = -1206.79
## final  value -1206.787046 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1110.6  |proj g|=           20
## At iterate    10  f =      -1205.9  |proj g|=        2.2844
## At iterate    20  f =      -1206.8  |proj g|=      0.030964
## At iterate    30  f =      -1206.8  |proj g|=      0.043404
## 
## iterations 30
## function evaluations 46
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0434041
## final function value -1206.79
## 
## F = -1206.79
## final  value -1206.787058 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1198.2  |proj g|=       7.4644
## At iterate    10  f =      -1198.3  |proj g|=       0.12936
## At iterate    20  f =      -1198.5  |proj g|=       0.97199
## 
## iterations 26
## function evaluations 38
## segments explored during Cauchy searches 26
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00353227
## final function value -1198.53
## 
## F = -1198.53
## final  value -1198.525335 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1105.6  |proj g|=           20
## At iterate    10  f =      -1197.5  |proj g|=         2.153
## At iterate    20  f =      -1198.3  |proj g|=         1.033
## At iterate    30  f =      -1198.5  |proj g|=        1.7823
## 
## iterations 39
## function evaluations 49
## segments explored during Cauchy searches 41
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00564842
## final function value -1198.53
## 
## F = -1198.53
## final  value -1198.525340 
## converged
## 
print(est.denver.2.1.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 8 converged, 2 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv     eigen.min eigen.all.min
## 1  1195.171        TRUE  TRUE  0.0027248826            NA
## 2  1203.321        TRUE FALSE -0.0007856017            NA
## 3  1211.813        TRUE  TRUE  0.0002833296            NA
## 4  1176.129        TRUE  TRUE  0.0009372763            NA
## 5  1194.459        TRUE  TRUE  0.0011933004            NA
## 6  1218.154        TRUE  TRUE  0.0027018484            NA
## 7  1212.158        TRUE  TRUE  0.0002879147            NA
## 8  1200.047        TRUE FALSE -0.0019051334            NA
## 9  1206.787        TRUE  TRUE  0.0026855117            NA
## 10 1198.525        TRUE  TRUE  0.0003758222            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.2.1, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.2.1.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.2, denver.model.2.1, est.denver.model.2.1, est.denver.2.1.cv,
     file = here::here("Results", "Denver_ST_Model_2.1.rdata"))

7.1.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.2.1.cv <- predictCV(denver.model.2.1, est.denver.2.1.cv, LTA = T)
pred.2.1.cv.log <- predictCV(denver.model.2.1, est.denver.2.1.cv,
                             LTA = T, transform="unbiased")

names(pred.2.1.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.2.1.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.10878883 0.10878883 0.10878883
## average 0.05785825 0.05785825 0.05785825
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.7213060  0.7213060 0.7213060
## average 0.8533817  0.8533817 0.8533817
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9578606
## average 0.8166667
summary(pred.2.1.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.12789740 0.12789740 0.12791058 0.12841997
## average 0.06298178 0.06298178 0.06300588 0.06387939
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.7467105  0.7467105 0.7466583 0.7446364
## average 0.8932699  0.8932699 0.8931883 0.8902061
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9578606
## average 0.8166667
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.1.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.1.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod2.1.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.1.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.1.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

7.2 Model 2.2: Smoothing in the error term

7.2.1 Create the model object

For this version of the model, use iid for cov.beta (beta, beta1, beta2) and exp for cov.nu (error). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data2.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR2.2 <- list(covar_fun, covar_fun, covar_fun)

cov.beta2.2 <-  list(covf = c("iid", "iid", "iid"), nugget = T)
cov.nu2.2 <- list(covf = "exp", nugget = T, random.effect = FALSE)
locations2.2 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.2.2 <- createSTmodel(denver.data2.2, LUR = LUR2.2,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta2.2, cov.nu = cov.nu2.2,
                                  locations = locations2.2)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.2.2
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, iid, iid 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

7.2.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.2.2, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.nugget.V1.iid"            
## [3] "log.nugget.V2.iid"             "nu.log.range.exp"             
## [5] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# x.init.2.2 <- cbind(c(0, 0, 0, 0, 0, 0),
#                     c(-1, -1, -1, 0, -1, -1),
#                     c(-1, -1, -1, 0, -5, -1),
#                     c(-5, -5, -5, 0, -1, -5),
#                     c(-5, -5, -5, 0, -5, -5),
#                     c(-1, -1, -1, 2, -1, -1),
#                     c(-1, -1, -1, 2, -5, -1),
#                     c(-5, -5, -5, 2, -1, -5),
#                     c(-5, -5, -5, 2, -5, -5),
#                     c(-1, -1, -1, 4, -1, -1),
#                     c(-1, -1, -1, 4, -5, -1),
#                     c(-5, -5, -5, 4, -1, -5),
#                     c(-5, -5, -5, 4, -5, -5))

x.init.2.2 <- cbind(c(0, 0, 0, 0, 0, 0),
                    c(-10, -5, -5, 4, -3, -5),
                    c(-10, -5, -5, 4, -5, -5),
                    c(-10, -5, -5, 6, -3, -5),
                    c(-10, -5, -5, 6, -5, -5),
                    c(-10, -5, -5, 8, -3, -5),
                    c(-10, -5, -5, 8, -5, -5),
                    c(-10, -5, -5, 10, -3, -5),
                    c(-10, -5, -5, 10, -5, -5))

rownames(x.init.2.2) <- loglikeSTnames(denver.model.2.2, all=FALSE)
x.init.2.2
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## log.nugget.const.iid             0  -10  -10  -10  -10  -10  -10  -10  -10
## log.nugget.V1.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## log.nugget.V2.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## nu.log.range.exp                 0    4    4    6    6    8    8   10   10
## nu.log.sill.exp                  0   -3   -5   -3   -5   -3   -5   -3   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5   -5   -5   -5   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.2.2 <- estimate.STmodel(denver.model.2.2, x.init.2.2)
## Optimisation using starting value 1/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       373.19  |proj g|=           15
## At iterate    10  f =      -1314.1  |proj g|=       0.52062
## At iterate    20  f =      -1314.8  |proj g|=      0.031687
## 
## iterations 28
## function evaluations 51
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0731776
## final function value -1314.76
## 
## F = -1314.76
## l(0) > u(0).  No feasible solutionfinal  value -1314.757143 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -992.7  |proj g|=           12
## At iterate    10  f =      -1314.4  |proj g|=        3.3565
## At iterate    20  f =      -1314.6  |proj g|=       0.82945
## At iterate    30  f =      -1314.8  |proj g|=       0.27145
## At iterate    40  f =      -1522.3  |proj g|=        7.6047
## 
## iterations 49
## function evaluations 79
## segments explored during Cauchy searches 52
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0270587
## final function value -1529.36
## 
## F = -1529.36
## l(0) > u(0).  No feasible solutionfinal  value -1529.361394 
## converged
## Optimisation using starting value 3/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1273  |proj g|=           10
## At iterate    10  f =      -1314.5  |proj g|=       0.63572
## At iterate    20  f =      -1314.8  |proj g|=       0.41225
## ys=-5.917e+00  -gs= 9.483e-01, BFGS update SKIPPED
## At iterate    30  f =        -1511  |proj g|=        10.914
## At iterate    40  f =      -1522.1  |proj g|=        11.587
## At iterate    50  f =      -1529.4  |proj g|=    0.00026429
## 
## iterations 50
## function evaluations 75
## segments explored during Cauchy searches 53
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000264285
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.361380 
## converged
## Optimisation using starting value 4/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -995.32  |proj g|=           12
## At iterate    10  f =      -1501.8  |proj g|=        20.994
## At iterate    20  f =      -1528.8  |proj g|=       0.50275
## At iterate    30  f =      -1529.4  |proj g|=       0.20295
## 
## iterations 38
## function evaluations 46
## segments explored during Cauchy searches 41
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000939653
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.361380 
## converged
## Optimisation using starting value 5/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1275.6  |proj g|=           10
## At iterate    10  f =      -1465.2  |proj g|=        5.0306
## At iterate    20  f =      -1510.6  |proj g|=        3.0076
## At iterate    30  f =      -1516.1  |proj g|=        2.9596
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 37
## function evaluations 73
## segments explored during Cauchy searches 41
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0105217
## final function value -1516.2
## 
## F = -1516.2
## final  value -1516.200208 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1042.6  |proj g|=           12
## At iterate    10  f =      -1528.9  |proj g|=        1.6927
## At iterate    20  f =      -1529.3  |proj g|=        1.5037
## At iterate    30  f =      -1529.4  |proj g|=       0.15363
## 
## iterations 35
## function evaluations 40
## segments explored during Cauchy searches 39
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000508873
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.361379 
## converged
## Optimisation using starting value 7/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1311.2  |proj g|=           10
## At iterate    10  f =      -1528.3  |proj g|=         2.651
## At iterate    20  f =      -1529.3  |proj g|=        1.4353
## At iterate    30  f =      -1529.4  |proj g|=       0.15061
## 
## iterations 32
## function evaluations 36
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.049243
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.361389 
## converged
## Optimisation using starting value 8/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1226.3  |proj g|=           12
## At iterate    10  f =      -1528.4  |proj g|=         2.069
## At iterate    20  f =      -1529.2  |proj g|=        2.2492
## At iterate    30  f =      -1529.4  |proj g|=       0.07006
## 
## iterations 33
## function evaluations 38
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0117792
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.361373 
## converged
## Optimisation using starting value 9/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1391.6  |proj g|=           10
## At iterate    10  f =      -1528.8  |proj g|=        3.3286
## At iterate    20  f =      -1529.3  |proj g|=       0.47258
## At iterate    30  f =      -1529.4  |proj g|=     0.0036242
## 
## iterations 30
## function evaluations 35
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00362422
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.361381 
## converged
print(est.denver.model.2.2)
## Optimisation for STmodel with 9 starting points.
##   Results: 7 converged, 2 not converged, 0 failed.
##   Best result for starting point 2, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0167178371   0.0188641801   0.0188649594
## alpha.const.(Intercept)          -0.0023941123  -0.0153445573  -0.0153629458
## alpha.const.impervious_2500       0.0511946658   0.0644170472   0.0644164849
## alpha.const.open_2500             0.0165191710   0.0287457842   0.0287454196
## alpha.const.low_int_100           0.0078027202   0.0206092360   0.0206092570
## alpha.const.med_int_50            0.0068278700  -0.0052694315  -0.0052697162
## alpha.const.high_int_50           0.0170835614   0.0058669489   0.0058673447
## alpha.const.high_int_100         -0.0229321489  -0.0004826128  -0.0004829139
## alpha.const.ag_250               -0.0041466670  -0.0014450737  -0.0014449839
## alpha.const.pop_den_50            0.0054019842   0.0025489691   0.0025495190
## alpha.const.dist_m_compost        0.0055453384   0.0003495273   0.0003493290
## alpha.const.dist_m_military       0.0184139943   0.0064141510   0.0064139055
## alpha.const.len_m_highways_2500  -0.0001176760   0.0052956483   0.0052953507
## alpha.const.aadt_100              0.0359014428   0.0221516452   0.0221515051
## alpha.const.aadt_2500            -0.0002897697  -0.0101701214  -0.0101698113
## alpha.V1.(Intercept)             -0.2832639391  -0.2888044095  -0.2887987461
## alpha.V1.impervious_2500         -0.0538925467  -0.0569410302  -0.0569428921
## alpha.V1.open_2500               -0.0428549312  -0.0383384482  -0.0383391993
## alpha.V1.low_int_100             -0.0009233514  -0.0078504821  -0.0078498161
## alpha.V1.med_int_50              -0.0061212662  -0.0046109945  -0.0046119668
## alpha.V1.high_int_50              0.0136712039  -0.0004849858  -0.0004859046
## alpha.V1.high_int_100            -0.0414450433  -0.0132490281  -0.0132462405
## alpha.V1.ag_250                  -0.0114267756   0.0123916375   0.0123924663
## alpha.V1.pop_den_50              -0.0164335999  -0.0024255504  -0.0024251109
## alpha.V1.dist_m_compost          -0.0274899284  -0.0044438787  -0.0044444681
## alpha.V1.dist_m_military         -0.0137789782   0.0077961998   0.0077953472
## alpha.V1.len_m_highways_2500      0.0058153002   0.0124351383   0.0124357130
## alpha.V1.aadt_100                 0.0214565643   0.0177776148   0.0177773300
## alpha.V1.aadt_2500                0.0061636681   0.0139496405   0.0139493719
## alpha.V2.(Intercept)             -0.1844440524  -0.1132910848  -0.1132911796
## alpha.V2.impervious_2500         -0.0106953189  -0.0064320634  -0.0064339563
## alpha.V2.open_2500                0.0110412875   0.0188187682   0.0188176145
## alpha.V2.low_int_100              0.0011806003   0.0040758040   0.0040763484
## alpha.V2.med_int_50              -0.0007847904  -0.0154232661  -0.0154243458
## alpha.V2.high_int_50             -0.0019828726  -0.0332713051  -0.0332720862
## alpha.V2.high_int_100            -0.0493223430   0.0160181438   0.0160207516
## alpha.V2.ag_250                  -0.0305571512  -0.0043079616  -0.0043071663
## alpha.V2.pop_den_50              -0.0006418036   0.0085878496   0.0085878672
## alpha.V2.dist_m_compost           0.0047987968   0.0275715461   0.0275711262
## alpha.V2.dist_m_military          0.0114280177   0.0272008871   0.0272002664
## alpha.V2.len_m_highways_2500      0.0123520570   0.0250451455   0.0250457370
## alpha.V2.aadt_100                 0.0133554966  -0.0200256221  -0.0200257825
## alpha.V2.aadt_2500               -0.0037448912  -0.0021628516  -0.0021626173
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid                -8.5819052016  -6.6195394716  -6.6194588227
## log.nugget.V2.iid                -7.5758084289  -6.0799574427  -6.0796174495
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -5.9498357881  -3.8036100306  -3.8038358223
## nu.log.nugget.(Intercept).exp    -4.6918202492  -5.6743012893  -5.6744148264
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0188650090   0.0182446096   0.0188650571
## alpha.const.(Intercept)          -0.0153641136  -0.0061183813  -0.0153652621
## alpha.const.impervious_2500       0.0644163893   0.0462520592   0.0644164508
## alpha.const.open_2500             0.0287453319   0.0089559249   0.0287454111
## alpha.const.low_int_100           0.0206092204   0.0096963722   0.0206092710
## alpha.const.med_int_50           -0.0052697387  -0.0080788818  -0.0052697335
## alpha.const.high_int_50           0.0058673749   0.0024339504   0.0058673849
## alpha.const.high_int_100         -0.0004829428   0.0014015390  -0.0004829505
## alpha.const.ag_250               -0.0014450019  -0.0018280345  -0.0014449616
## alpha.const.pop_den_50            0.0025495496   0.0012400774   0.0025495863
## alpha.const.dist_m_compost        0.0003492960   0.0005288068   0.0003493198
## alpha.const.dist_m_military       0.0064138918   0.0106437757   0.0064138818
## alpha.const.len_m_highways_2500   0.0052953405   0.0123808520   0.0052953123
## alpha.const.aadt_100              0.0221514748   0.0162127991   0.0221514978
## alpha.const.aadt_2500            -0.0101697729  -0.0061645962  -0.0101697880
## alpha.V1.(Intercept)             -0.2887983802  -0.2938803962  -0.2887980903
## alpha.V1.impervious_2500         -0.0569431499  -0.0470195416  -0.0569429867
## alpha.V1.open_2500               -0.0383394182  -0.0313062856  -0.0383391746
## alpha.V1.low_int_100             -0.0078497968  -0.0051952266  -0.0078497394
## alpha.V1.med_int_50              -0.0046120500  -0.0008864757  -0.0046120459
## alpha.V1.high_int_50             -0.0004859083   0.0046862932  -0.0004860215
## alpha.V1.high_int_100            -0.0132461454  -0.0240577691  -0.0132459431
## alpha.V1.ag_250                   0.0123923670   0.0053539855   0.0123926296
## alpha.V1.pop_den_50              -0.0024251509  -0.0046464967  -0.0024250315
## alpha.V1.dist_m_compost          -0.0044446542  -0.0075885582  -0.0044444505
## alpha.V1.dist_m_military          0.0077952052   0.0054214030   0.0077953124
## alpha.V1.len_m_highways_2500      0.0124357213   0.0059037222   0.0124357780
## alpha.V1.aadt_100                 0.0177772639   0.0196342260   0.0177773291
## alpha.V1.aadt_2500                0.0139493397   0.0111659191   0.0139493535
## alpha.V2.(Intercept)             -0.1132911642  -0.1181778064  -0.1132912827
## alpha.V2.impervious_2500         -0.0064342484  -0.0114627248  -0.0064340332
## alpha.V2.open_2500                0.0188173226   0.0092412397   0.0188176258
## alpha.V2.low_int_100              0.0040763119  -0.0035213280   0.0040764314
## alpha.V2.med_int_50              -0.0154244165  -0.0134727783  -0.0154244405
## alpha.V2.high_int_50             -0.0332720671  -0.0303916496  -0.0332722019
## alpha.V2.high_int_100             0.0160208053   0.0062763201   0.0160210529
## alpha.V2.ag_250                  -0.0043072826  -0.0118084512  -0.0043070035
## alpha.V2.pop_den_50               0.0085877796   0.0057420963   0.0085879188
## alpha.V2.dist_m_compost           0.0275709348   0.0244255800   0.0275711787
## alpha.V2.dist_m_military          0.0272001504   0.0274775772   0.0272002485
## alpha.V2.len_m_highways_2500      0.0250457577   0.0236969020   0.0250457943
## alpha.V2.aadt_100                -0.0200258591  -0.0234114579  -0.0200257530
## alpha.V2.aadt_2500               -0.0021625911  -0.0015586164  -0.0021626037
## log.nugget.const.iid            -15.0000000000  -7.1133105988 -15.0000000000
## log.nugget.V1.iid                -6.6194660217 -14.8576399569  -6.6194294754
## log.nugget.V2.iid                -6.0795616544  -6.6217359181  -6.0795902358
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8038442693  -3.8162036054  -3.8038486934
## nu.log.nugget.(Intercept).exp    -5.6744119277  -5.5614698608  -5.6744148359
##                                           [,7]           [,8]           [,9]
## gamma.bc_st_no2                   0.0188626702   0.0188657851   0.0188649271
## alpha.const.(Intercept)          -0.0153093144  -0.0153828385  -0.0153620506
## alpha.const.impervious_2500       0.0644162966   0.0644148098   0.0644163374
## alpha.const.open_2500             0.0287443786   0.0287437503   0.0287452798
## alpha.const.low_int_100           0.0206072373   0.0206078594   0.0206093292
## alpha.const.med_int_50           -0.0052679644  -0.0052691198  -0.0052699587
## alpha.const.high_int_50           0.0058659066   0.0058674554   0.0058674410
## alpha.const.high_int_100         -0.0004826416  -0.0004837010  -0.0004828565
## alpha.const.ag_250               -0.0014462031  -0.0014455274  -0.0014450033
## alpha.const.pop_den_50            0.0025474713   0.0025497467   0.0025495511
## alpha.const.dist_m_compost        0.0003495130   0.0003489621   0.0003492271
## alpha.const.dist_m_military       0.0064152434   0.0064141982   0.0064137933
## alpha.const.len_m_highways_2500   0.0052967807   0.0052954599   0.0052953222
## alpha.const.aadt_100              0.0221510768   0.0221508010   0.0221514917
## alpha.const.aadt_2500            -0.0101704342  -0.0101694112  -0.0101697056
## alpha.V1.(Intercept)             -0.2888186754  -0.2887958601  -0.2887981749
## alpha.V1.impervious_2500         -0.0569380212  -0.0569439574  -0.0569440567
## alpha.V1.open_2500               -0.0383412268  -0.0383421305  -0.0383398917
## alpha.V1.low_int_100             -0.0078538882  -0.0078508343  -0.0078495873
## alpha.V1.med_int_50              -0.0046077611  -0.0046115168  -0.0046124481
## alpha.V1.high_int_50             -0.0004793964  -0.0004839144  -0.0004861972
## alpha.V1.high_int_100            -0.0132638323  -0.0132511614  -0.0132450142
## alpha.V1.ag_250                   0.0123831500   0.0123885488   0.0123925040
## alpha.V1.pop_den_50              -0.0024296237  -0.0024269243  -0.0024250632
## alpha.V1.dist_m_compost          -0.0044472043  -0.0044476812  -0.0044448906
## alpha.V1.dist_m_military          0.0077964284   0.0077940450   0.0077948399
## alpha.V1.len_m_highways_2500      0.0124315306   0.0124343016   0.0124359815
## alpha.V1.aadt_100                 0.0177770872   0.0177765270   0.0177771152
## alpha.V1.aadt_2500                0.0139500985   0.0139491890   0.0139492473
## alpha.V2.(Intercept)             -0.1132954935  -0.1132957777  -0.1132899070
## alpha.V2.impervious_2500         -0.0064298697  -0.0064355252  -0.0064352403
## alpha.V2.open_2500                0.0188158779   0.0188139273   0.0188166738
## alpha.V2.low_int_100              0.0040706556   0.0040738679   0.0040765608
## alpha.V2.med_int_50              -0.0154185796  -0.0154230561  -0.0154249161
## alpha.V2.high_int_50             -0.0332660542  -0.0332701646  -0.0332722288
## alpha.V2.high_int_100             0.0160033363   0.0160156275   0.0160217700
## alpha.V2.ag_250                  -0.0043171858  -0.0043117096  -0.0043070892
## alpha.V2.pop_den_50               0.0085848033   0.0085860188   0.0085876791
## alpha.V2.dist_m_compost           0.0275676618   0.0275680473   0.0275705902
## alpha.V2.dist_m_military          0.0272006483   0.0271990760   0.0271998643
## alpha.V2.len_m_highways_2500      0.0250416547   0.0250443643   0.0250460826
## alpha.V2.aadt_100                -0.0200267145  -0.0200265612  -0.0200261107
## alpha.V2.aadt_2500               -0.0021635512  -0.0021627167  -0.0021624584
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid                -6.6210061720  -6.6201384835  -6.6193979659
## log.nugget.V2.iid                -6.0809351263  -6.0795890421  -6.0793344573
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8034317458  -3.8040552292  -3.8038225045
## nu.log.nugget.(Intercept).exp    -5.6741229518  -5.6743571774  -5.6744145913
## 
## Function value(s):
## [1] 1314.757 1529.361 1529.361 1529.361 1516.200 1529.361 1529.361 1529.361
## [9] 1529.361

7.2.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.2.2 <- createCV(denver.model.2.2, groups = 10, #min.dist = .1,
                           subset = paste0("d_", c(1:60)))

ID.cv.2.2 <- sapply(split(denver.model.2.2$obs$ID, Ind.cv.2.2), unique)
print(sapply(ID.cv.2.2, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.2.2)
## Ind.cv.2.2
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.2.2 <- apply(sapply(ID.cv.2.2, function(x) denver.model.2.2$locations$ID%in% x), 1,
                       function(x) if(sum(x)==1) which(x) else 0)
names(I.col.2.2) <- denver.model.2.2$locations$ID
print(I.col.2.2)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.2.2$locations$long,
     denver.model.2.2$locations$lat,
     pch=23+floor(I.col.2.2/max(I.col.2.2)+.5), bg=I.col.2.2,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.2.2.cv <- coef(est.denver.model.2.2, pars="cov")[,c("par","init")]
x.init.2.2.cv

Run the model with cross validation

est.denver.2.2.cv <- estimateCV(denver.model.2.2, x.init.2.2.cv, Ind.cv.2.2)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1391.3  |proj g|=       2.0526
## 
## iterations 6
## function evaluations 8
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00371078
## final function value -1391.9
## 
## F = -1391.9
## final  value -1391.896863 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -908.14  |proj g|=           12
## At iterate    10  f =      -1194.8  |proj g|=        2.4165
## At iterate    20  f =      -1195.2  |proj g|=        1.9897
## At iterate    30  f =      -1195.4  |proj g|=       0.20295
## At iterate    40  f =        -1313  |proj g|=        11.463
## At iterate    50  f =      -1382.7  |proj g|=      0.016295
## At iterate    60  f =      -1390.5  |proj g|=        9.4494
## At iterate    70  f =      -1391.9  |proj g|=      0.010868
## At iterate    80  f =      -1391.9  |proj g|=      0.027597
## 
## iterations 80
## function evaluations 132
## segments explored during Cauchy searches 83
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.027597
## final function value -1391.9
## 
## F = -1391.9
## l(0) > u(0).  No feasible solutionfinal  value -1391.896863 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1397.6  |proj g|=        2.464
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 8
## function evaluations 39
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.014745
## final function value -1397.71
## 
## F = -1397.71
## final  value -1397.713466 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -912.64  |proj g|=           12
## At iterate    10  f =      -1203.1  |proj g|=       0.87886
## At iterate    20  f =      -1203.3  |proj g|=       0.17237
## At iterate    30  f =      -1203.5  |proj g|=        3.7254
## ys=-1.872e+01  -gs= 1.215e+00, BFGS update SKIPPED
## At iterate    40  f =      -1299.7  |proj g|=        11.355
## At iterate    50  f =      -1385.4  |proj g|=       0.91894
## At iterate    60  f =      -1396.4  |proj g|=         9.428
## 
## iterations 69
## function evaluations 102
## segments explored during Cauchy searches 73
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00866697
## final function value -1397.71
## 
## F = -1397.71
## final  value -1397.708745 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=        -1402  |proj g|=       2.5337
## 
## iterations 9
## function evaluations 13
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0381683
## final function value -1402.57
## 
## F = -1402.57
## final  value -1402.565378 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -916.29  |proj g|=           12
## At iterate    10  f =        -1212  |proj g|=       0.49988
## At iterate    20  f =      -1212.3  |proj g|=       0.14101
## ys=-5.055e+00  -gs= 1.451e-01, BFGS update SKIPPED
## At iterate    30  f =      -1221.2  |proj g|=        8.0724
## At iterate    40  f =      -1371.5  |proj g|=        4.1221
## At iterate    50  f =      -1389.8  |proj g|=      0.073181
## At iterate    60  f =      -1394.2  |proj g|=       0.17579
## 
## iterations 68
## function evaluations 99
## segments explored during Cauchy searches 71
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0570444
## final function value -1394.23
## 
## F = -1394.23
## final  value -1394.227582 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1365.2  |proj g|=       1.6265
## At iterate    10  f =      -1365.2  |proj g|=      0.065006
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 14
## function evaluations 65
## segments explored during Cauchy searches 16
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0102575
## final function value -1365.22
## 
## F = -1365.22
## final  value -1365.222479 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -894.39  |proj g|=           12
## At iterate    10  f =        -1176  |proj g|=        2.4527
## At iterate    20  f =      -1176.5  |proj g|=        1.9563
## ys=-5.514e+01  -gs= 4.333e-01, BFGS update SKIPPED
## At iterate    30  f =      -1296.4  |proj g|=        10.287
## At iterate    40  f =        -1355  |proj g|=      0.070227
## At iterate    50  f =      -1365.1  |proj g|=        1.6059
## 
## iterations 55
## function evaluations 83
## segments explored during Cauchy searches 58
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0390904
## final function value -1365.22
## 
## F = -1365.22
## final  value -1365.222496 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1378.2  |proj g|=        7.778
## At iterate    10  f =      -1378.8  |proj g|=      0.056146
## 
## iterations 13
## function evaluations 23
## segments explored during Cauchy searches 13
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0327784
## final function value -1378.76
## 
## F = -1378.76
## final  value -1378.763731 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -904.84  |proj g|=           12
## At iterate    10  f =      -1194.7  |proj g|=       0.86812
## At iterate    20  f =      -1195.2  |proj g|=       0.46078
## At iterate    30  f =      -1271.9  |proj g|=        20.883
## ys=-1.494e+00  -gs= 4.260e+00, BFGS update SKIPPED
## At iterate    40  f =        -1364  |proj g|=        13.558
## 
## iterations 43
## function evaluations 60
## segments explored during Cauchy searches 46
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0377052
## final function value -1364.44
## 
## F = -1364.44
## final  value -1364.440811 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1412.7  |proj g|=       5.6007
## At iterate    10  f =      -1412.9  |proj g|=    0.00071684
## 
## iterations 10
## function evaluations 12
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00071684
## final function value -1412.87
## 
## F = -1412.87
## final  value -1412.866616 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -925.52  |proj g|=           12
## At iterate    10  f =        -1218  |proj g|=       0.81097
## At iterate    20  f =      -1218.4  |proj g|=        1.2486
## At iterate    30  f =      -1218.5  |proj g|=       0.60373
## ys=-1.511e+00  -gs= 6.171e-01, BFGS update SKIPPED
## At iterate    40  f =      -1398.5  |proj g|=        20.622
## ys=-3.313e-01  -gs= 4.582e-01, BFGS update SKIPPED
## At iterate    50  f =      -1412.8  |proj g|=        2.1899
## 
## iterations 57
## function evaluations 94
## segments explored during Cauchy searches 60
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0337933
## final function value -1412.87
## 
## F = -1412.87
## l(0) > u(0).  No feasible solutionfinal  value -1412.866632 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1404.1  |proj g|=       4.4189
## At iterate    10  f =      -1404.6  |proj g|=      0.001901
## 
## iterations 11
## function evaluations 13
## segments explored during Cauchy searches 11
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00130977
## final function value -1404.56
## 
## F = -1404.56
## final  value -1404.555706 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -917.98  |proj g|=           12
## At iterate    10  f =      -1211.4  |proj g|=        2.0745
## ys=-3.580e-01  -gs= 1.105e+00, BFGS update SKIPPED
## At iterate    20  f =      -1304.9  |proj g|=        7.4922
## At iterate    30  f =      -1397.7  |proj g|=       0.17362
## ys=-1.002e+01  -gs= 1.925e-01, BFGS update SKIPPED
## At iterate    40  f =      -1403.3  |proj g|=        9.1422
## 
## iterations 49
## function evaluations 73
## segments explored during Cauchy searches 52
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0424246
## final function value -1404.56
## 
## F = -1404.56
## final  value -1404.555685 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1399.2  |proj g|=       3.1434
## At iterate    10  f =      -1399.3  |proj g|=     0.0029507
## 
## iterations 10
## function evaluations 15
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00295069
## final function value -1399.3
## 
## F = -1399.3
## final  value -1399.299547 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -911.55  |proj g|=           12
## At iterate    10  f =      -1199.9  |proj g|=        2.4288
## At iterate    20  f =      -1200.2  |proj g|=       0.69535
## At iterate    30  f =      -1200.4  |proj g|=       0.47043
## At iterate    40  f =      -1328.7  |proj g|=        21.116
## At iterate    50  f =      -1385.7  |proj g|=      0.038265
## At iterate    60  f =      -1397.7  |proj g|=        9.4399
## At iterate    70  f =      -1399.3  |proj g|=      0.024742
## 
## iterations 72
## function evaluations 98
## segments explored during Cauchy searches 75
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00503363
## final function value -1399.3
## 
## F = -1399.3
## final  value -1399.298330 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1402.1  |proj g|=        4.431
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## At iterate    10  f =      -1402.1  |proj g|=      0.019294
## 
## iterations 10
## function evaluations 44
## segments explored during Cauchy searches 11
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0192937
## final function value -1402.14
## 
## F = -1402.14
## l(0) > u(0).  No feasible solutionfinal  value -1402.140762 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -918.59  |proj g|=           12
## At iterate    10  f =      -1206.8  |proj g|=        2.2261
## At iterate    20  f =        -1207  |proj g|=         2.324
## At iterate    30  f =      -1207.1  |proj g|=       0.21781
## 
## iterations 36
## function evaluations 49
## segments explored during Cauchy searches 39
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00427842
## final function value -1207.09
## 
## F = -1207.09
## final  value -1207.089772 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1389.4  |proj g|=       1.0344
## 
## iterations 8
## function evaluations 21
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0657244
## final function value -1389.49
## 
## F = -1389.49
## l(0) > u(0).  No feasible solutionfinal  value -1389.490145 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -909.46  |proj g|=           12
## At iterate    10  f =      -1198.4  |proj g|=        4.5217
## At iterate    20  f =      -1198.6  |proj g|=       0.68389
## At iterate    30  f =        -1199  |proj g|=        1.1037
## ys=-4.069e-01  -gs= 2.063e-01, BFGS update SKIPPED
## At iterate    40  f =      -1263.1  |proj g|=        10.329
## At iterate    50  f =      -1379.3  |proj g|=      0.016986
## 
## iterations 52
## function evaluations 68
## segments explored during Cauchy searches 55
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00517967
## final function value -1379.31
## 
## F = -1379.31
## final  value -1379.309551 
## converged
## 
print(est.denver.2.2.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 10 converged, 0 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence conv   eigen.min eigen.all.min
## 1  1391.897        TRUE TRUE 0.003464776            NA
## 2  1397.713        TRUE TRUE 0.003796052            NA
## 3  1402.565        TRUE TRUE 0.004111330            NA
## 4  1365.222        TRUE TRUE 0.003560943            NA
## 5  1378.764        TRUE TRUE 0.004592848            NA
## 6  1412.867        TRUE TRUE 0.005159925            NA
## 7  1404.556        TRUE TRUE 0.003662124            NA
## 8  1399.300        TRUE TRUE 0.003954698            NA
## 9  1402.141        TRUE TRUE 0.003997159            NA
## 10 1389.490        TRUE TRUE 0.003719513            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.2.2, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
             col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.2.2.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.2, denver.model.2.2, est.denver.model.2.2, est.denver.2.2.cv,
     file = here::here("Results", "Denver_ST_Model_2.2.rdata"))

7.2.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.2.2.cv <- predictCV(denver.model.2.2, est.denver.2.2.cv, LTA = T)
pred.2.2.cv.log <- predictCV(denver.model.2.2, est.denver.2.2.cv,
                             LTA = T, transform="unbiased")

names(pred.2.2.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.2.2.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.12090640 0.12090640 0.09286316
## average 0.07505008 0.07505008 0.06278566
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6557630  0.6557630 0.7969300
## average 0.7533053  0.7533053 0.8273453
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9205835
## average 0.9000000
summary(pred.2.2.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.14478680 0.14478680 0.10730231 0.10746498
## average 0.08624894 0.08624894 0.07026172 0.07062303
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6753976  0.6753976 0.8217162 0.8211752
## average 0.7998459  0.7998459 0.8671705 0.8658009
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9205835
## average 0.9333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.2.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.2.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod2.2.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.2.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.2.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

7.3 Model 2.3: Smoothing in beta0 and the error term

7.3.1 Create the model object

For this version of the model, use iid for cov.beta (beta1, beta2) and exp for cov.beta (beta0) and cov.nu (error). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data2.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR2.3 <- list(covar_fun, covar_fun, covar_fun)

cov.beta2.3 <-  list(covf = c("exp", "iid", "iid"), nugget = c(T, T, T))
cov.nu2.3 <- list(covf = "exp", nugget = T, random.effect = FALSE)
locations2.3 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.2.3 <- createSTmodel(denver.data2.2, LUR = LUR2.3,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta2.3, cov.nu = cov.nu2.3,
                                  locations = locations2.3)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.2.3
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): exp, iid, iid 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

7.3.2 Estimate model parameters

Josh gave some guidance on how to set up the initial values (NOTE: the iid model doesn’t have range or sill values, but the exp model does):

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.2.3, all=FALSE)
names
## [1] "log.range.const.exp"           "log.sill.const.exp"           
## [3] "log.nugget.const.exp"          "log.nugget.V1.iid"            
## [5] "log.nugget.V2.iid"             "nu.log.range.exp"             
## [7] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# x.init.2.3 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0),
#                     c(0, -1, -1, -1, -1, 0, -1, -1),
#                     c(0, -1, -5, -5, -5, 0, -1, -1),
#                     c(0, -5, -1, -1, -1, 0, -5, -5),
#                     c(0, -5, -5, -5, -5, 0, -5, -5),
#                     c(2, -1, -1, -1, -1, 2, -1, -1),
#                     c(2, -1, -5, -5, -5, 2, -1, -1),
#                     c(2, -5, -1, -1, -1, 2, -5, -5),
#                     c(2, -5, -5, -5, -5, 2, -5, -5),
#                     c(4, -1, -1, -1, -1, 4, -1, -1),
#                     c(4, -1, -5, -5, -5, 4, -1, -1),
#                     c(4, -5, -1, -1, -1, 4, -5, -5),
#                     c(4, -5, -5, -5, -5, 4, -5, -5),
#                     c(6, -1, -1, -1, -1, 6, -1, -1),
#                     c(6, -1, -5, -5, -5, 6, -1, -1),
#                     c(6, -5, -1, -1, -1, 6, -5, -5),
#                     c(6, -5, -5, -5, -5, 6, -5, -5)
#                     )
# x.init.2.3[nrow(x.init.2.3),] <- 0

x.init.2.3 <- cbind(c(0, 0, 0, 0, 0, 0, 0),
                    c(4, -5, -5, -5, -5, 4, -5, -5),
                    c(4, -5, -5, -5, -5, 6, -5, -5),
                    c(4, -5, -5, -5, -5, 8, -5, -5),
                    c(4, -5, -5, -5, -5, 8, -5, -5),
                    c(4, -10, -10, -5, -5, 4, -5, -5),
                    c(4, -10, -10, -5, -5, 6, -5, -5),
                    c(4, -10, -10, -5, -5, 8, -5, -5),
                    c(4, -10, -10, -5, -5, 10, -5, -5)
                    )
## Warning in cbind(c(0, 0, 0, 0, 0, 0, 0), c(4, -5, -5, -5, -5, 4, -5, -5), :
## number of rows of result is not a multiple of vector length (arg 1)
rownames(x.init.2.3) <- loglikeSTnames(denver.model.2.3, all=FALSE)
x.init.2.3
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## log.range.const.exp              0    4    4    4    4    4    4    4    4
## log.sill.const.exp               0   -5   -5   -5   -5  -10  -10  -10  -10
## log.nugget.const.exp             0   -5   -5   -5   -5  -10  -10  -10  -10
## log.nugget.V1.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## log.nugget.V2.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## nu.log.range.exp                 0    4    6    8    8    4    6    8   10
## nu.log.sill.exp                  0   -5   -5   -5   -5   -5   -5   -5   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5   -5   -5   -5   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.2.3 <- estimate.STmodel(denver.model.2.3, x.init.2.3)
## Optimisation using starting value 1/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       384.97  |proj g|=           15
## At iterate    10  f =      -1313.1  |proj g|=       0.44006
## At iterate    20  f =      -1314.6  |proj g|=        1.3115
## At iterate    30  f =      -1314.7  |proj g|=       0.23666
## At iterate    40  f =      -1314.8  |proj g|=      0.013616
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1314.753751 
## stopped after 41 iterations
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1240  |proj g|=           10
## At iterate    10  f =      -1314.3  |proj g|=        1.7732
## At iterate    20  f =      -1314.7  |proj g|=       0.23612
## ys=-1.234e-01  -gs= 2.728e-02, BFGS update SKIPPED
## At iterate    30  f =      -1440.1  |proj g|=        20.685
## At iterate    40  f =        -1524  |proj g|=         9.999
## At iterate    50  f =      -1529.4  |proj g|=      0.011705
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1529.357147 
## stopped after 50 iterations
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1242.6  |proj g|=           10
## At iterate    10  f =      -1463.5  |proj g|=        10.003
## At iterate    20  f =      -1493.6  |proj g|=        9.8453
## At iterate    30  f =      -1513.5  |proj g|=       0.58227
## At iterate    40  f =      -1524.2  |proj g|=        9.6028
## At iterate    50  f =      -1529.3  |proj g|=        2.8278
## At iterate    60  f =      -1529.3  |proj g|=       0.46271
## 
## iterations 68
## function evaluations 106
## segments explored during Cauchy searches 71
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.006401
## final function value -1529.36
## 
## F = -1529.36
## l(0) > u(0).  No feasible solutionfinal  value -1529.357222 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1277.4  |proj g|=           10
## At iterate    10  f =      -1520.9  |proj g|=        3.3887
## At iterate    20  f =      -1528.1  |proj g|=        9.3694
## At iterate    30  f =      -1529.4  |proj g|=      0.023207
## At iterate    40  f =      -1529.4  |proj g|=      0.084451
## 
## iterations 45
## function evaluations 62
## segments explored during Cauchy searches 49
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0755648
## final function value -1529.36
## 
## F = -1529.36
## l(0) > u(0).  No feasible solutionfinal  value -1529.357241 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 5/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1277.4  |proj g|=           10
## At iterate    10  f =      -1520.9  |proj g|=        3.3887
## At iterate    20  f =      -1528.1  |proj g|=        9.3694
## At iterate    30  f =      -1529.4  |proj g|=      0.023207
## At iterate    40  f =      -1529.4  |proj g|=      0.084451
## 
## iterations 45
## function evaluations 62
## segments explored during Cauchy searches 49
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0755648
## final function value -1529.36
## 
## F = -1529.36
## l(0) > u(0).  No feasible solutionfinal  value -1529.357241 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1272.7  |proj g|=           10
## At iterate    10  f =      -1314.3  |proj g|=       0.86648
## At iterate    20  f =      -1314.8  |proj g|=       0.11046
## ys=-1.509e+00  -gs= 3.132e-01, BFGS update SKIPPED
## At iterate    30  f =      -1331.7  |proj g|=        16.579
## At iterate    40  f =      -1510.5  |proj g|=        19.374
## At iterate    50  f =      -1529.1  |proj g|=        2.3043
## 
## iterations 55
## function evaluations 86
## segments explored during Cauchy searches 58
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0227651
## final function value -1529.36
## 
## F = -1529.36
## l(0) > u(0).  No feasible solutionfinal  value -1529.356802 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 7/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1275.2  |proj g|=           10
## At iterate    10  f =      -1480.7  |proj g|=         20.44
## At iterate    20  f =      -1510.7  |proj g|=       0.86732
## ys=-2.608e+00  -gs= 8.511e-01, BFGS update SKIPPED
## At iterate    30  f =      -1513.9  |proj g|=        3.0791
## At iterate    40  f =      -1516.6  |proj g|=        0.1159
## 
## iterations 42
## function evaluations 53
## segments explored during Cauchy searches 45
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0177229
## final function value -1516.57
## 
## F = -1516.57
## final  value -1516.570434 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 8/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1310.8  |proj g|=           10
## At iterate    10  f =      -1527.8  |proj g|=        3.3054
## At iterate    20  f =      -1529.3  |proj g|=        1.0751
## At iterate    30  f =      -1529.4  |proj g|=      0.082095
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1529.356786 
## stopped after 30 iterations
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 9/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1391.2  |proj g|=           10
## At iterate    10  f =      -1528.4  |proj g|=        2.4064
## At iterate    20  f =      -1529.3  |proj g|=       0.18738
## 
## iterations 28
## function evaluations 35
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00454532
## final function value -1529.36
## 
## F = -1529.36
## final  value -1529.356833 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
print(est.denver.model.2.3)
## Optimisation for STmodel with 9 starting points.
##   Results: 0 converged, 9 not converged, 0 failed.
##   Best result for starting point 4, optimisation has NOT converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0167155714   0.0188651939   0.0188658766
## alpha.const.(Intercept)          -0.0023444731  -0.0153729748  -0.0153891646
## alpha.const.impervious_2500       0.0511818781   0.0644102280   0.0644106078
## alpha.const.open_2500             0.0165060443   0.0287395906   0.0287401707
## alpha.const.low_int_100           0.0077968466   0.0206051208   0.0206055352
## alpha.const.med_int_50            0.0068282502  -0.0052700813  -0.0052700524
## alpha.const.high_int_50           0.0170862860   0.0058652210   0.0058654538
## alpha.const.high_int_100         -0.0229347812  -0.0004801860  -0.0004804390
## alpha.const.ag_250               -0.0041465986  -0.0014447670  -0.0014444386
## alpha.const.pop_den_50            0.0053998755   0.0025503501   0.0025508155
## alpha.const.dist_m_compost        0.0055465699   0.0003507154   0.0003508193
## alpha.const.dist_m_military       0.0184136435   0.0064164896   0.0064163157
## alpha.const.len_m_highways_2500  -0.0001145360   0.0052976886   0.0052973315
## alpha.const.aadt_100              0.0359013840   0.0221482022   0.0221483683
## alpha.const.aadt_2500            -0.0002880982  -0.0101678215  -0.0101678811
## alpha.V1.(Intercept)             -0.2832720542  -0.2887964202  -0.2887922557
## alpha.V1.impervious_2500         -0.0538774450  -0.0569391826  -0.0569383637
## alpha.V1.open_2500               -0.0428486774  -0.0383361422  -0.0383344801
## alpha.V1.low_int_100             -0.0009259369  -0.0078481880  -0.0078476310
## alpha.V1.med_int_50              -0.0061179563  -0.0046114614  -0.0046116383
## alpha.V1.high_int_50              0.0136771337  -0.0004846296  -0.0004857158
## alpha.V1.high_int_100            -0.0414694340  -0.0132486860  -0.0132465711
## alpha.V1.ag_250                  -0.0114331888   0.0123921643   0.0123943701
## alpha.V1.pop_den_50              -0.0164311972  -0.0024254941  -0.0024244736
## alpha.V1.dist_m_compost          -0.0274957418  -0.0044447376  -0.0044433479
## alpha.V1.dist_m_military         -0.0137806472   0.0077950515   0.0077956824
## alpha.V1.len_m_highways_2500      0.0058099010   0.0124342285   0.0124347828
## alpha.V1.aadt_100                 0.0214566240   0.0177782922   0.0177787138
## alpha.V1.aadt_2500                0.0061604349   0.0139482097   0.0139482708
## alpha.V2.(Intercept)             -0.1844318215  -0.1132942652  -0.1132956593
## alpha.V2.impervious_2500         -0.0106681196  -0.0064343860  -0.0064330765
## alpha.V2.open_2500                0.0110496702   0.0188162258   0.0188183371
## alpha.V2.low_int_100              0.0011690498   0.0040740826   0.0040751090
## alpha.V2.med_int_50              -0.0007693054  -0.0154237578  -0.0154241424
## alpha.V2.high_int_50             -0.0019457198  -0.0332720472  -0.0332732710
## alpha.V2.high_int_100            -0.0494081470   0.0160189744   0.0160214123
## alpha.V2.ag_250                  -0.0305633547  -0.0043074791  -0.0043051888
## alpha.V2.pop_den_50              -0.0006421116   0.0085883526   0.0085894236
## alpha.V2.dist_m_compost           0.0047880167   0.0275719812   0.0275737574
## alpha.V2.dist_m_military          0.0114216657   0.0272015926   0.0272021802
## alpha.V2.len_m_highways_2500      0.0123453326   0.0250457490   0.0250461045
## alpha.V2.aadt_100                 0.0133976443  -0.0200262996  -0.0200254546
## alpha.V2.aadt_2500               -0.0037456361  -0.0021623069  -0.0021623736
## log.range.const.exp               0.0000000000   4.0039928761   4.0214011646
## log.sill.const.exp              -14.8865939849 -14.9903398511 -15.0000000000
## log.nugget.const.exp            -15.0000000000 -14.9907182717 -15.0000000000
## log.nugget.V1.iid                -8.5828829948  -6.6196091981  -6.6192922743
## log.nugget.V2.iid                -7.5797732205  -6.0797674795  -6.0799020626
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -5.9267157863  -3.8037810482  -3.8038678560
## nu.log.nugget.(Intercept).exp    -4.6985327867  -5.6743536914  -5.6743762211
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0188639964   0.0188639964   0.0188662979
## alpha.const.(Intercept)          -0.0153448292  -0.0153448292  -0.0153985358
## alpha.const.impervious_2500       0.0644120400   0.0644120400   0.0644074940
## alpha.const.open_2500             0.0287411255   0.0287411255   0.0287372205
## alpha.const.low_int_100           0.0206054912   0.0206054912   0.0206049929
## alpha.const.med_int_50           -0.0052693048  -0.0052693048  -0.0052720685
## alpha.const.high_int_50           0.0058644708   0.0058644708   0.0058663486
## alpha.const.high_int_100         -0.0004797170  -0.0004797170  -0.0004802313
## alpha.const.ag_250               -0.0014446368  -0.0014446368  -0.0014449004
## alpha.const.pop_den_50            0.0025494793   0.0025494793   0.0025514741
## alpha.const.dist_m_compost        0.0003513357   0.0003513357   0.0003497214
## alpha.const.dist_m_military       0.0064169347   0.0064169347   0.0064156125
## alpha.const.len_m_highways_2500   0.0052980528   0.0052980528   0.0052972652
## alpha.const.aadt_100              0.0221487242   0.0221487242   0.0221475054
## alpha.const.aadt_2500            -0.0101686678  -0.0101686678  -0.0101663807
## alpha.V1.(Intercept)             -0.2888061082  -0.2888061082  -0.2887834113
## alpha.V1.impervious_2500         -0.0569334980  -0.0569334980  -0.0569500908
## alpha.V1.open_2500               -0.0383323936  -0.0383323936  -0.0383426506
## alpha.V1.low_int_100             -0.0078492819  -0.0078492819  -0.0078457587
## alpha.V1.med_int_50              -0.0046091591  -0.0046091591  -0.0046161104
## alpha.V1.high_int_50             -0.0004834589  -0.0004834589  -0.0004874100
## alpha.V1.high_int_100            -0.0132535511  -0.0132535511  -0.0132374588
## alpha.V1.ag_250                   0.0123924501   0.0123924501   0.0123925761
## alpha.V1.pop_den_50              -0.0024255064  -0.0024255064  -0.0024250277
## alpha.V1.dist_m_compost          -0.0044417296  -0.0044417296  -0.0044494194
## alpha.V1.dist_m_military          0.0077979194   0.0077979194   0.0077898854
## alpha.V1.len_m_highways_2500      0.0124333471   0.0124333471   0.0124364764
## alpha.V1.aadt_100                 0.0177794831   0.0177794831   0.0177762196
## alpha.V1.aadt_2500                0.0139489593   0.0139489593   0.0139468110
## alpha.V2.(Intercept)             -0.1132957346  -0.1132957346  -0.1132867790
## alpha.V2.impervious_2500         -0.0064280883  -0.0064280883  -0.0064466300
## alpha.V2.open_2500                0.0188214850   0.0188214850   0.0188068530
## alpha.V2.low_int_100              0.0040737862   0.0040737862   0.0040755566
## alpha.V2.med_int_50              -0.0154213948  -0.0154213948  -0.0154289643
## alpha.V2.high_int_50             -0.0332713901  -0.0332713901  -0.0332736800
## alpha.V2.high_int_100             0.0160149338   0.0160149338   0.0160284759
## alpha.V2.ag_250                  -0.0043070274  -0.0043070274  -0.0043069956
## alpha.V2.pop_den_50               0.0085894795   0.0085894795   0.0085866005
## alpha.V2.dist_m_compost           0.0275750015   0.0275750015   0.0275668556
## alpha.V2.dist_m_military          0.0272038245   0.0272038245   0.0271976537
## alpha.V2.len_m_highways_2500      0.0250446021   0.0250446021   0.0250486881
## alpha.V2.aadt_100                -0.0200249493  -0.0200249493  -0.0200291101
## alpha.V2.aadt_2500               -0.0021629837  -0.0021629837  -0.0021608464
## log.range.const.exp               4.0083757171   4.0083757171   4.0024398048
## log.sill.const.exp              -15.0000000000 -15.0000000000 -14.9533743186
## log.nugget.const.exp            -15.0000000000 -15.0000000000 -14.9537508853
## log.nugget.V1.iid                -6.6194720391  -6.6194720391  -6.6191926738
## log.nugget.V2.iid                -6.0807902765  -6.0807902765  -6.0772241772
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8033060093  -3.8033060093  -3.8040029135
## nu.log.nugget.(Intercept).exp    -5.6740859397  -5.6740859397  -5.6744377287
##                                           [,7]           [,8]           [,9]
## gamma.bc_st_no2                   0.0183052582   0.0188675120   0.0188653007
## alpha.const.(Intercept)          -0.0091751552  -0.0154284550  -0.0153757441
## alpha.const.impervious_2500       0.0454515295   0.0644091072   0.0644100245
## alpha.const.open_2500             0.0082616156   0.0287391045   0.0287394899
## alpha.const.low_int_100           0.0095097945   0.0206050592   0.0206051687
## alpha.const.med_int_50           -0.0086087441  -0.0052702722  -0.0052703106
## alpha.const.high_int_50           0.0018141152   0.0058658590   0.0058651607
## alpha.const.high_int_100          0.0024060785  -0.0004808280  -0.0004799077
## alpha.const.ag_250               -0.0017970210  -0.0014441797  -0.0014445750
## alpha.const.pop_den_50            0.0014217485   0.0025519586   0.0025505512
## alpha.const.dist_m_compost        0.0005854712   0.0003507543   0.0003508588
## alpha.const.dist_m_military       0.0107799152   0.0064162779   0.0064165371
## alpha.const.len_m_highways_2500   0.0126352026   0.0052970230   0.0052977258
## alpha.const.aadt_100              0.0151862894   0.0221477762   0.0221480867
## alpha.const.aadt_2500            -0.0059843279  -0.0101672342  -0.0101676885
## alpha.V1.(Intercept)             -0.2927360706  -0.2887815862  -0.2887950054
## alpha.V1.impervious_2500         -0.0465548857  -0.0569396979  -0.0569390615
## alpha.V1.open_2500               -0.0307470555  -0.0383343765  -0.0383352915
## alpha.V1.low_int_100             -0.0050820634  -0.0078464618  -0.0078476176
## alpha.V1.med_int_50              -0.0006494811  -0.0046127440  -0.0046117867
## alpha.V1.high_int_50              0.0045857124  -0.0004870112  -0.0004853155
## alpha.V1.high_int_100            -0.0240451570  -0.0132431133  -0.0132468657
## alpha.V1.ag_250                   0.0057002506   0.0123960967   0.0123934396
## alpha.V1.pop_den_50              -0.0043659407  -0.0024236394  -0.0024249076
## alpha.V1.dist_m_compost          -0.0072977669  -0.0044437294  -0.0044440598
## alpha.V1.dist_m_military          0.0056147836   0.0077948414   0.0077951635
## alpha.V1.len_m_highways_2500      0.0058764842   0.0124353773   0.0124346305
## alpha.V1.aadt_100                 0.0195676414   0.0177786388   0.0177785127
## alpha.V1.aadt_2500                0.0110434403   0.0139478222   0.0139481014
## alpha.V2.(Intercept)             -0.1185661180  -0.1132982204  -0.1132936597
## alpha.V2.impervious_2500         -0.0113648293  -0.0064346933  -0.0064344165
## alpha.V2.open_2500                0.0093383002   0.0188176013   0.0188168577
## alpha.V2.low_int_100             -0.0036272723   0.0040756934   0.0040747015
## alpha.V2.med_int_50              -0.0135588240  -0.0154253335  -0.0154243099
## alpha.V2.high_int_50             -0.0306504916  -0.0332746761  -0.0332727889
## alpha.V2.high_int_100             0.0064547294   0.0160249424   0.0160208746
## alpha.V2.ag_250                  -0.0114749751  -0.0043035773  -0.0043060676
## alpha.V2.pop_den_50               0.0060394230   0.0085899026   0.0085889094
## alpha.V2.dist_m_compost           0.0247068175   0.0275740324   0.0275727961
## alpha.V2.dist_m_military          0.0277387310   0.0272017987   0.0272018548
## alpha.V2.len_m_highways_2500      0.0238520242   0.0250467590   0.0250462370
## alpha.V2.aadt_100                -0.0237010444  -0.0200252397  -0.0200261169
## alpha.V2.aadt_2500               -0.0015443551  -0.0021621354  -0.0021622098
## log.range.const.exp               4.3769067703   4.0047719388   4.0046568278
## log.sill.const.exp               -7.0495986943 -14.8952602172 -14.9112082517
## log.nugget.const.exp            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid               -14.8935203373  -6.6187338715  -6.6194486964
## log.nugget.V2.iid                -6.6398960969  -6.0792259986  -6.0797429873
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8166088315  -3.8038444956  -3.8038260256
## nu.log.nugget.(Intercept).exp    -5.5635423738  -5.6741112720  -5.6744234516
## 
## Function value(s):
## [1] 1314.754 1529.357 1529.357 1529.357 1529.357 1529.357 1516.570 1529.357
## [9] 1529.357

7.3.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.2.3 <- createCV(denver.model.2.3, groups = 10, #min.dist = .1,
                           subset = paste0("d_", c(1:60)))

ID.cv.2.3 <- sapply(split(denver.model.2.3$obs$ID, Ind.cv.2.3), unique)
print(sapply(ID.cv.2.3, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.2.3)
## Ind.cv.2.3
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.2.3 <- apply(sapply(ID.cv.2.3, function(x) denver.model.2.3$locations$ID%in% x), 1,
                       function(x) if(sum(x)==1) which(x) else 0)
names(I.col.2.3) <- denver.model.2.3$locations$ID
print(I.col.2.3)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.2.3$locations$long,
     denver.model.2.3$locations$lat,
     pch=23+floor(I.col.2.3/max(I.col.2.3)+.5), bg=I.col.2.3,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.2.3.cv <- coef(est.denver.model.2.3, pars="cov")[,c("par","init")]
x.init.2.3.cv

Run the model with cross validation

est.denver.2.3.cv <- estimateCV(denver.model.2.3, x.init.2.3.cv, Ind.cv.2.3)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1391.3  |proj g|=       2.0565
## 
## iterations 6
## function evaluations 8
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00309611
## final function value -1391.89
## 
## F = -1391.89
## final  value -1391.893532 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1160.6  |proj g|=           10
## At iterate    10  f =      -1386.6  |proj g|=        2.2867
## At iterate    20  f =      -1390.9  |proj g|=         4.682
## At iterate    30  f =      -1391.9  |proj g|=      0.014142
## 
## iterations 33
## function evaluations 39
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0196407
## final function value -1391.89
## 
## F = -1391.89
## final  value -1391.893415 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1397.6  |proj g|=       2.5062
## At iterate    10  f =      -1397.7  |proj g|=     0.0021193
## 
## iterations 11
## function evaluations 22
## segments explored during Cauchy searches 11
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00211928
## final function value -1397.71
## 
## F = -1397.71
## final  value -1397.709567 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1169  |proj g|=           10
## At iterate    10  f =      -1393.9  |proj g|=        7.1636
## At iterate    20  f =      -1397.5  |proj g|=        1.0603
## At iterate    30  f =      -1397.7  |proj g|=     0.0041788
## 
## iterations 30
## function evaluations 35
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00417877
## final function value -1397.71
## 
## F = -1397.71
## final  value -1397.709340 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=        -1402  |proj g|=       2.4893
## 
## iterations 9
## function evaluations 12
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0131572
## final function value -1402.56
## 
## F = -1402.56
## final  value -1402.561492 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1170.6  |proj g|=           10
## At iterate    10  f =      -1398.3  |proj g|=        9.7444
## At iterate    20  f =      -1401.4  |proj g|=        1.5694
## At iterate    30  f =      -1402.4  |proj g|=        0.6606
## At iterate    40  f =      -1402.5  |proj g|=       0.44565
## At iterate    50  f =      -1402.6  |proj g|=       0.05337
## 
## iterations 54
## function evaluations 61
## segments explored during Cauchy searches 59
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0178274
## final function value -1402.56
## 
## F = -1402.56
## final  value -1402.561187 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1365.2  |proj g|=       1.6468
## At iterate    10  f =      -1365.2  |proj g|=      0.057928
## 
## iterations 10
## function evaluations 13
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0579281
## final function value -1365.22
## 
## F = -1365.22
## final  value -1365.218813 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1139.8  |proj g|=           10
## At iterate    10  f =      -1359.8  |proj g|=        5.2766
## At iterate    20  f =        -1365  |proj g|=       0.68756
## At iterate    30  f =      -1365.2  |proj g|=       0.13231
## 
## iterations 34
## function evaluations 48
## segments explored during Cauchy searches 38
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.012629
## final function value -1365.22
## 
## F = -1365.22
## final  value -1365.218374 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1378.2  |proj g|=       7.7329
## At iterate    10  f =      -1378.8  |proj g|=      0.057321
## 
## iterations 13
## function evaluations 33
## segments explored during Cauchy searches 13
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0144806
## final function value -1378.76
## 
## F = -1378.76
## l(0) > u(0).  No feasible solutionfinal  value -1378.759266 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1154.2  |proj g|=           10
## At iterate    10  f =      -1371.8  |proj g|=         9.246
## At iterate    20  f =      -1378.4  |proj g|=        1.4454
## At iterate    30  f =      -1378.8  |proj g|=      0.024717
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1378.759045 
## stopped after 33 iterations
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1412.7  |proj g|=       5.5559
## At iterate    10  f =      -1412.9  |proj g|=    0.00038129
## 
## iterations 10
## function evaluations 12
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.000381295
## final function value -1412.86
## 
## F = -1412.86
## final  value -1412.861715 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1186.3  |proj g|=           10
## At iterate    10  f =      -1406.6  |proj g|=        5.3176
## At iterate    20  f =      -1412.7  |proj g|=        3.7279
## At iterate    30  f =      -1412.9  |proj g|=     0.0059189
## 
## iterations 38
## function evaluations 55
## segments explored during Cauchy searches 42
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0313279
## final function value -1412.86
## 
## F = -1412.86
## final  value -1412.861729 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=        -1404  |proj g|=       4.3721
## At iterate    10  f =      -1404.6  |proj g|=     0.0060527
## 
## iterations 12
## function evaluations 15
## segments explored during Cauchy searches 12
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00595394
## final function value -1404.55
## 
## F = -1404.55
## final  value -1404.552251 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1176.6  |proj g|=           10
## At iterate    10  f =      -1398.4  |proj g|=        6.5591
## At iterate    20  f =      -1404.5  |proj g|=        2.2685
## At iterate    30  f =      -1404.6  |proj g|=      0.010237
## 
## iterations 31
## function evaluations 45
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0102375
## final function value -1404.55
## 
## F = -1404.55
## final  value -1404.552252 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1399.2  |proj g|=       3.1863
## At iterate    10  f =      -1399.3  |proj g|=     0.0029676
## 
## iterations 10
## function evaluations 15
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00296758
## final function value -1399.3
## 
## F = -1399.3
## final  value -1399.295776 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1163.7  |proj g|=           10
## At iterate    10  f =      -1396.1  |proj g|=        2.7766
## At iterate    20  f =      -1399.2  |proj g|=        2.3573
## 
## iterations 29
## function evaluations 34
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00407775
## final function value -1399.3
## 
## F = -1399.3
## final  value -1399.295512 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1402.1  |proj g|=        4.386
## At iterate    10  f =      -1402.1  |proj g|=       0.02339
## 
## iterations 10
## function evaluations 23
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0233897
## final function value -1402.14
## 
## F = -1402.14
## l(0) > u(0).  No feasible solutionfinal  value -1402.136974 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1170.3  |proj g|=           10
## At iterate    10  f =      -1395.3  |proj g|=        5.5045
## At iterate    20  f =        -1402  |proj g|=        2.3019
## At iterate    30  f =      -1402.1  |proj g|=      0.012699
## 
## iterations 32
## function evaluations 38
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00412629
## final function value -1402.14
## 
## F = -1402.14
## final  value -1402.136691 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1389.4  |proj g|=       1.0282
## 
## iterations 8
## function evaluations 21
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0735237
## final function value -1389.49
## 
## F = -1389.49
## l(0) > u(0).  No feasible solutionfinal  value -1389.486368 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1162  |proj g|=           10
## At iterate    10  f =      -1381.9  |proj g|=         5.082
## At iterate    20  f =      -1388.3  |proj g|=        2.0629
## At iterate    30  f =      -1389.4  |proj g|=       0.55056
## At iterate    40  f =      -1389.5  |proj g|=       0.04645
## 
## iterations 42
## function evaluations 46
## segments explored during Cauchy searches 46
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00426311
## final function value -1389.49
## 
## F = -1389.49
## final  value -1389.485920 
## converged
## 
print(est.denver.2.3.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 9 converged, 1 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv       eigen.min eigen.all.min
## 1  1391.894        TRUE  TRUE  0.000071345862            NA
## 2  1397.710        TRUE  TRUE  0.000308344291            NA
## 3  1402.561        TRUE  TRUE  0.000028224316            NA
## 4  1365.219        TRUE  TRUE  0.000033852891            NA
## 5  1378.759        TRUE  TRUE  0.000048544185            NA
## 6  1412.862        TRUE  TRUE  0.000124460771            NA
## 7  1404.552        TRUE FALSE -0.000071875297            NA
## 8  1399.296        TRUE  TRUE  0.000135546917            NA
## 9  1402.137        TRUE  TRUE  0.000019070470            NA
## 10 1389.486        TRUE  TRUE  0.000009720495            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.2.3, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
             col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.2.3.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.2, denver.model.2.3, est.denver.model.2.3, est.denver.2.3.cv,
     file = here::here("Results", "Denver_ST_Model_2.3.rdata"))

7.3.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.2.3.cv <- predictCV(denver.model.2.3, est.denver.2.3.cv, LTA = T)
pred.2.3.cv.log <- predictCV(denver.model.2.3, est.denver.2.3.cv,
                             LTA = T, transform="unbiased")

names(pred.2.3.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.2.3.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##             EX.mu EX.mu.beta         EX
## obs     0.1209066 0.12090656 0.09286351
## average 0.0750504 0.07505038 0.06278582
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6557620  0.6557621 0.7969284
## average 0.7533032  0.7533033 0.8273444
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9205835
## average 0.9000000
summary(pred.2.3.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.14478660 0.14478657 0.10730257 0.10746528
## average 0.08624879 0.08624874 0.07026138 0.07062275
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6753985  0.6753986 0.8217153 0.8211742
## average 0.7998466  0.7998469 0.8671718 0.8658020
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9205835
## average 0.9333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.3.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.3.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod2.3.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.3.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.3.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

7.4 Model 2.4: Smoothing for beta1, beta2 and the error term

7.4.1 Create the model object

For this version of the model, use iid for cov.beta (beta0) and exp for cov.beta (beta1, beta2) cov.nu (error).

names(denver.data2.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR2.4 <- list(covar_fun, covar_fun, covar_fun)

cov.beta2.4 <-  list(covf=c("iid", "exp", "exp"), nugget = c(TRUE, TRUE, TRUE))
cov.nu2.4 <- list(covf="exp", nugget = T, random.effect = FALSE)
locations2.4 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.2.4 <- createSTmodel(denver.data2.2, LUR = LUR2.4,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta2.4, cov.nu = cov.nu2.4,
                                  locations = locations2.4)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.2.4
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, exp, exp 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

7.4.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.2.4, all=FALSE)
names
##  [1] "log.nugget.const.iid"          "log.range.V1.exp"             
##  [3] "log.sill.V1.exp"               "log.nugget.V1.exp"            
##  [5] "log.range.V2.exp"              "log.sill.V2.exp"              
##  [7] "log.nugget.V2.exp"             "nu.log.range.exp"             
##  [9] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# 
# x.init.2.4 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
#                     c(-1, 0, -1, -1, 0, -1, -1, 0, -1, -1),
#                     c(-1, 0, -1, -5, 0, -5, -1, 0, -5, -1),
#                     c(-5, 0, -5, -1, 0, -1, -5, 0, -1, -5),
#                     c(-5, 0, -5, -5, 0, -5, -5, 0, -5, -5),
#                     c(-1, 2, -1, -1, 2, -1, -1, 2, -1, -1),
#                     c(-1, 2, -1, -5, 2, -5, -1, 2, -5, -1),
#                     c(-5, 2, -5, -1, 2, -1, -5, 2, -1, -5),
#                     c(-5, 2, -5, -5, 2, -5, -5, 2, -5, -5),
#                     c(-1, 4, -1, -1, 4, -1, -1, 4, -1, -1),
#                     c(-1, 4, -1, -5, 4, -5, -1, 4, -5, -1),
#                     c(-5, 4, -5, -5, 4, -1, -5, 4, -1, -5),
#                     c(-5, 4, -5, -5, 4, -5, -5, 4, -5, -5),
#                     c(-1, 6, -1, -1, 6, -1, -1, 6, -1, -1),
#                     c(-1, 6, -1, -5, 6, -5, -1, 6, -5, -1),
#                     c(-5, 6, -5, -5, 6, -1, -5, 6, -1, -5),
#                     c(-5, 6, -5, -5, 6, -5, -5, 6, -5, -5))
# x.init.2.4[nrow(x.init.2.4),] <- 0

x.init.2.4 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                    c(-5, 4, -5, -5, 6, -5, -5, 6, -5, -5),
                    c(-5, 4, -5, -5, 6, -5, -5, 6, -5, -5),
                    c(-10, 4, -10, -1, 6, -5, -10, 10, -5, -5),
                    c(-10, 4, -10, -5, 6, -5, -10, 10 -5, -5),
                    c(-13, 4, -10, -1, 6, -5, -13, 10, -5, -5),
                    c(-13, 4, -10, -5, 6, -5, -13, 10, -5, -5))
## Warning in cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), c(-5, 4, -5, -5, 6, -5, :
## number of rows of result is not a multiple of vector length (arg 5)
rownames(x.init.2.4) <- loglikeSTnames(denver.model.2.4, all=FALSE)
x.init.2.4
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## log.nugget.const.iid             0   -5   -5  -10  -10  -13  -13
## log.range.V1.exp                 0    4    4    4    4    4    4
## log.sill.V1.exp                  0   -5   -5  -10  -10  -10  -10
## log.nugget.V1.exp                0   -5   -5   -1   -5   -1   -5
## log.range.V2.exp                 0    6    6    6    6    6    6
## log.sill.V2.exp                  0   -5   -5   -5   -5   -5   -5
## log.nugget.V2.exp                0   -5   -5  -10  -10  -13  -13
## nu.log.range.exp                 0    6    6   10    5   10   10
## nu.log.sill.exp                  0   -5   -5   -5   -5   -5   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5  -10   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.2.4 <- estimate.STmodel(denver.model.2.4, x.init.2.4)
## Optimisation using starting value 1/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       395.16  |proj g|=           15
## At iterate    10  f =      -1314.3  |proj g|=        2.2829
## At iterate    20  f =      -1314.6  |proj g|=       0.74597
## At iterate    30  f =      -1314.7  |proj g|=       0.40146
## At iterate    40  f =      -1314.7  |proj g|=       0.25113
## 
## iterations 43
## function evaluations 61
## segments explored during Cauchy searches 45
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0864805
## final function value -1314.75
## 
## F = -1314.75
## final  value -1314.748581 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1237  |proj g|=           10
## At iterate    10  f =      -1465.4  |proj g|=        5.8517
## At iterate    20  f =      -1513.1  |proj g|=        6.4906
## At iterate    30  f =      -1515.1  |proj g|=        6.9881
## At iterate    40  f =      -1529.2  |proj g|=      0.084252
## At iterate    50  f =      -1529.3  |proj g|=       0.62611
## At iterate    60  f =      -1529.4  |proj g|=       0.48568
## At iterate    70  f =      -1529.7  |proj g|=       0.28921
## At iterate    80  f =      -1529.8  |proj g|=       0.87929
## ys=-8.923e-03  -gs= 1.084e-02, BFGS update SKIPPED
## At iterate    90  f =      -1529.8  |proj g|=      0.080839
## At iterate   100  f =      -1530.6  |proj g|=        0.3575
## 
## iterations 104
## function evaluations 129
## segments explored during Cauchy searches 107
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.061952
## final function value -1530.57
## 
## F = -1530.57
## final  value -1530.568370 
## converged
## Optimisation using starting value 3/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1237  |proj g|=           10
## At iterate    10  f =      -1465.4  |proj g|=        5.8517
## At iterate    20  f =      -1513.1  |proj g|=        6.4906
## At iterate    30  f =      -1515.1  |proj g|=        6.9881
## At iterate    40  f =      -1529.2  |proj g|=      0.084252
## At iterate    50  f =      -1529.3  |proj g|=       0.62611
## At iterate    60  f =      -1529.4  |proj g|=       0.48568
## At iterate    70  f =      -1529.7  |proj g|=       0.28921
## At iterate    80  f =      -1529.8  |proj g|=       0.87929
## ys=-8.923e-03  -gs= 1.084e-02, BFGS update SKIPPED
## At iterate    90  f =      -1529.8  |proj g|=      0.080839
## At iterate   100  f =      -1530.6  |proj g|=        0.3575
## 
## iterations 104
## function evaluations 129
## segments explored during Cauchy searches 107
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.061952
## final function value -1530.57
## 
## F = -1530.57
## final  value -1530.568370 
## converged
## Optimisation using starting value 4/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1292.2  |proj g|=           14
## At iterate    10  f =      -1529.6  |proj g|=        5.2707
## At iterate    20  f =      -1530.2  |proj g|=       0.59119
## At iterate    30  f =      -1530.5  |proj g|=       0.46548
## At iterate    40  f =      -1530.5  |proj g|=       0.17714
## 
## iterations 45
## function evaluations 65
## segments explored during Cauchy searches 48
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0394435
## final function value -1530.54
## 
## F = -1530.54
## l(0) > u(0).  No feasible solutionfinal  value -1530.537395 
## converged
## Optimisation using starting value 5/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -39.595  |proj g|=           25
## At iterate    10  f =      -1387.3  |proj g|=         21.57
## At iterate    20  f =      -1511.7  |proj g|=        18.912
## At iterate    30  f =      -1528.3  |proj g|=        1.8975
## At iterate    40  f =        -1529  |proj g|=       0.11836
## 
## iterations 47
## function evaluations 75
## segments explored during Cauchy searches 50
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0151069
## final function value -1529.04
## 
## F = -1529.04
## l(0) > u(0).  No feasible solutionfinal  value -1529.040341 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1292.6  |proj g|=           14
## At iterate    10  f =      -1530.1  |proj g|=        4.3053
## At iterate    20  f =      -1530.5  |proj g|=       0.32566
## At iterate    30  f =      -1530.5  |proj g|=      0.057107
## At iterate    40  f =      -1530.6  |proj g|=      0.085839
## 
## iterations 48
## function evaluations 65
## segments explored during Cauchy searches 51
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0229939
## final function value -1530.56
## 
## F = -1530.56
## final  value -1530.561516 
## converged
## Optimisation using starting value 7/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1392.6  |proj g|=           10
## At iterate    10  f =      -1530.5  |proj g|=       0.49678
## At iterate    20  f =      -1530.5  |proj g|=       0.04411
## At iterate    30  f =      -1530.6  |proj g|=       0.48914
## 
## iterations 37
## function evaluations 53
## segments explored during Cauchy searches 41
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0837226
## final function value -1530.56
## 
## F = -1530.56
## l(0) > u(0).  No feasible solutionfinal  value -1530.561518 
## converged
print(est.denver.model.2.4)
## Optimisation for STmodel with 7 starting points.
##   Results: 5 converged, 2 not converged, 0 failed.
##   Best result for starting point 2, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0167183849   0.0188386177   0.0188386177
## alpha.const.(Intercept)          -0.0024055222  -0.0149661116  -0.0149661116
## alpha.const.impervious_2500       0.0512137538   0.0647466558   0.0647466558
## alpha.const.open_2500             0.0165379836   0.0290059811   0.0290059811
## alpha.const.low_int_100           0.0078118024   0.0207637300   0.0207637300
## alpha.const.med_int_50            0.0068268951  -0.0054055006  -0.0054055006
## alpha.const.high_int_50           0.0170857775   0.0059549585   0.0059549585
## alpha.const.high_int_100         -0.0229369416  -0.0005419889  -0.0005419889
## alpha.const.ag_250               -0.0041414588  -0.0013462510  -0.0013462510
## alpha.const.pop_den_50            0.0054027048   0.0025343583   0.0025343583
## alpha.const.dist_m_compost        0.0055475808   0.0002931633   0.0002931633
## alpha.const.dist_m_military       0.0184178620   0.0063471090   0.0063471090
## alpha.const.len_m_highways_2500  -0.0001145131   0.0051849758   0.0051849758
## alpha.const.aadt_100              0.0359055315   0.0223347146   0.0223347146
## alpha.const.aadt_2500            -0.0002945172  -0.0100955236  -0.0100955236
## alpha.V1.(Intercept)             -0.2832664125  -0.2863954025  -0.2863954025
## alpha.V1.impervious_2500         -0.0538912331  -0.0568352117  -0.0568352117
## alpha.V1.open_2500               -0.0428293027  -0.0381445752  -0.0381445752
## alpha.V1.low_int_100             -0.0009229021  -0.0074459325  -0.0074459325
## alpha.V1.med_int_50              -0.0061155743  -0.0047397378  -0.0047397378
## alpha.V1.high_int_50              0.0136529898  -0.0002830345  -0.0002830345
## alpha.V1.high_int_100            -0.0414176286  -0.0129950626  -0.0129950626
## alpha.V1.ag_250                  -0.0113798385   0.0130603605   0.0130603605
## alpha.V1.pop_den_50              -0.0164044090  -0.0027187544  -0.0027187544
## alpha.V1.dist_m_compost          -0.0274524172  -0.0045502478  -0.0045502478
## alpha.V1.dist_m_military         -0.0137512139   0.0076389578   0.0076389578
## alpha.V1.len_m_highways_2500      0.0058385417   0.0122277048   0.0122277048
## alpha.V1.aadt_100                 0.0214180287   0.0186800871   0.0186800871
## alpha.V1.aadt_2500                0.0061706607   0.0142020336   0.0142020336
## alpha.V2.(Intercept)             -0.1844500832  -0.1094508089  -0.1094508089
## alpha.V2.impervious_2500         -0.0106606249  -0.0029866899  -0.0029866899
## alpha.V2.open_2500                0.0110917653   0.0218237486   0.0218237486
## alpha.V2.low_int_100              0.0011851303   0.0052586363   0.0052586363
## alpha.V2.med_int_50              -0.0007696453  -0.0144865549  -0.0144865549
## alpha.V2.high_int_50             -0.0019822699  -0.0303741716  -0.0303741716
## alpha.V2.high_int_100            -0.0493419811   0.0136623227   0.0136623227
## alpha.V2.ag_250                  -0.0305038935  -0.0027198663  -0.0027198663
## alpha.V2.pop_den_50              -0.0006236763   0.0069949259   0.0069949259
## alpha.V2.dist_m_compost           0.0048320190   0.0263657565   0.0263657565
## alpha.V2.dist_m_military          0.0114568120   0.0273465649   0.0273465649
## alpha.V2.len_m_highways_2500      0.0123803104   0.0227162966   0.0227162966
## alpha.V2.aadt_100                 0.0133637214  -0.0169507078  -0.0169507078
## alpha.V2.aadt_2500               -0.0037515291  -0.0009616315  -0.0009616315
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.range.V1.exp                  0.0000000000   3.8710847893   3.8710847893
## log.sill.V1.exp                 -12.0988222175 -15.0000000000 -15.0000000000
## log.nugget.V1.exp                -8.6037574447  -6.6045429676  -6.6045429676
## log.range.V2.exp                  0.0000000000   6.4042656551   6.4042656551
## log.sill.V2.exp                 -12.4650225164  -6.0453933851  -6.0453933851
## log.nugget.V2.exp                -7.5724599296 -15.0000000000 -15.0000000000
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -5.9274958360  -3.8022965447  -3.8022965447
## nu.log.nugget.(Intercept).exp    -4.6982910030  -5.6793768941  -5.6793768941
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0188393007   0.0188267141   0.0188368255
## alpha.const.(Intercept)          -0.0149421454  -0.0124383326  -0.0149050056
## alpha.const.impervious_2500       0.0647414769   0.0643401365   0.0647470537
## alpha.const.open_2500             0.0290030978   0.0287077703   0.0290074926
## alpha.const.low_int_100           0.0207638882   0.0205141649   0.0207668968
## alpha.const.med_int_50           -0.0054077351  -0.0052777673  -0.0054087751
## alpha.const.high_int_50           0.0059521026   0.0056248176   0.0059534905
## alpha.const.high_int_100         -0.0005357166  -0.0002062198  -0.0005363537
## alpha.const.ag_250               -0.0013443965  -0.0013865915  -0.0013445041
## alpha.const.pop_den_50            0.0025390270   0.0027212195   0.0025354051
## alpha.const.dist_m_compost        0.0002945801   0.0004347940   0.0002940510
## alpha.const.dist_m_military       0.0063478593   0.0065583979   0.0063462395
## alpha.const.len_m_highways_2500   0.0051861887   0.0053991053   0.0051858960
## alpha.const.aadt_100              0.0223239582   0.0215701384   0.0223310052
## alpha.const.aadt_2500            -0.0100951986  -0.0101700845  -0.0100959139
## alpha.V1.(Intercept)             -0.2863971333  -0.2910377003  -0.2863824203
## alpha.V1.impervious_2500         -0.0568723897  -0.0582295076  -0.0568518565
## alpha.V1.open_2500               -0.0381629863  -0.0391843356  -0.0381489507
## alpha.V1.low_int_100             -0.0074503574  -0.0082666255  -0.0074448133
## alpha.V1.med_int_50              -0.0047576695  -0.0051505503  -0.0047494211
## alpha.V1.high_int_50             -0.0003369797  -0.0027010001  -0.0003110339
## alpha.V1.high_int_100            -0.0129081909  -0.0101685317  -0.0129433053
## alpha.V1.ag_250                   0.0130741743   0.0127820743   0.0130737549
## alpha.V1.pop_den_50              -0.0026849393  -0.0010481791  -0.0027020184
## alpha.V1.dist_m_compost          -0.0045324844  -0.0036901058  -0.0045382837
## alpha.V1.dist_m_military          0.0076540015   0.0087081354   0.0076464259
## alpha.V1.len_m_highways_2500      0.0122450027   0.0129139962   0.0122373143
## alpha.V1.aadt_100                 0.0185714057   0.0123620334   0.0186346660
## alpha.V1.aadt_2500                0.0141965688   0.0138734152   0.0142004008
## alpha.V2.(Intercept)             -0.1093596147  -0.1118362674  -0.1093538303
## alpha.V2.impervious_2500         -0.0030364647  -0.0074210432  -0.0030058204
## alpha.V2.open_2500                0.0217888515   0.0181031076   0.0218131296
## alpha.V2.low_int_100              0.0052485581   0.0034313217   0.0052556078
## alpha.V2.med_int_50              -0.0145050815  -0.0157515654  -0.0144956118
## alpha.V2.high_int_50             -0.0304517613  -0.0353595849  -0.0304014697
## alpha.V2.high_int_100             0.0137588156   0.0187963341   0.0137050020
## alpha.V2.ag_250                  -0.0027097640  -0.0038423302  -0.0027080290
## alpha.V2.pop_den_50               0.0070321110   0.0099263097   0.0070082738
## alpha.V2.dist_m_compost           0.0263915999   0.0283567950   0.0263781264
## alpha.V2.dist_m_military          0.0273632530   0.0283056072   0.0273547419
## alpha.V2.len_m_highways_2500      0.0227466443   0.0255741893   0.0227322377
## alpha.V2.aadt_100                -0.0170594386  -0.0252197630  -0.0169887217
## alpha.V2.aadt_2500               -0.0009677410  -0.0021882060  -0.0009649941
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.range.V1.exp                  3.9980334023   3.9646340405   3.9927035759
## log.sill.V1.exp                 -10.1773481691  -6.6399804590 -10.8300497126
## log.nugget.V1.exp                -6.6306315106 -13.1826131185  -6.6169210519
## log.range.V2.exp                  6.4066827772   6.1992169642   6.4015315355
## log.sill.V2.exp                  -6.0535322403 -11.2330122807  -6.0442749733
## log.nugget.V2.exp               -10.5524947169  -6.0816707839 -13.1199833924
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8023969542  -3.8024115983  -3.8019693015
## nu.log.nugget.(Intercept).exp    -5.6795948223  -5.6721041006  -5.6797154385
##                                           [,7]
## gamma.bc_st_no2                   0.0188388927
## alpha.const.(Intercept)          -0.0149558428
## alpha.const.impervious_2500       0.0647487820
## alpha.const.open_2500             0.0290091043
## alpha.const.low_int_100           0.0207656888
## alpha.const.med_int_50           -0.0054061032
## alpha.const.high_int_50           0.0059534356
## alpha.const.high_int_100         -0.0005390468
## alpha.const.ag_250               -0.0013438023
## alpha.const.pop_den_50            0.0025365182
## alpha.const.dist_m_compost        0.0002947418
## alpha.const.dist_m_military       0.0063474883
## alpha.const.len_m_highways_2500   0.0051850919
## alpha.const.aadt_100              0.0223315123
## alpha.const.aadt_2500            -0.0100962431
## alpha.V1.(Intercept)             -0.2863772441
## alpha.V1.impervious_2500         -0.0568420126
## alpha.V1.open_2500               -0.0381425259
## alpha.V1.low_int_100             -0.0074458252
## alpha.V1.med_int_50              -0.0047461349
## alpha.V1.high_int_50             -0.0003084307
## alpha.V1.high_int_100            -0.0129543631
## alpha.V1.ag_250                   0.0130762159
## alpha.V1.pop_den_50              -0.0027016751
## alpha.V1.dist_m_compost          -0.0045349782
## alpha.V1.dist_m_military          0.0076504921
## alpha.V1.len_m_highways_2500      0.0122350426
## alpha.V1.aadt_100                 0.0186366624
## alpha.V1.aadt_2500                0.0142018772
## alpha.V2.(Intercept)             -0.1093742436
## alpha.V2.impervious_2500         -0.0029873211
## alpha.V2.open_2500                0.0218310468
## alpha.V2.low_int_100              0.0052604513
## alpha.V2.med_int_50              -0.0144911133
## alpha.V2.high_int_50             -0.0303991462
## alpha.V2.high_int_100             0.0136985613
## alpha.V2.ag_250                  -0.0027015045
## alpha.V2.pop_den_50               0.0070124852
## alpha.V2.dist_m_compost           0.0263821048
## alpha.V2.dist_m_military          0.0273586537
## alpha.V2.len_m_highways_2500      0.0227238921
## alpha.V2.aadt_100                -0.0169859366
## alpha.V2.aadt_2500               -0.0009608660
## log.nugget.const.iid            -15.0000000000
## log.range.V1.exp                  3.9932161780
## log.sill.V1.exp                 -10.8308822436
## log.nugget.V1.exp                -6.6171211998
## log.range.V2.exp                  6.4053302605
## log.sill.V2.exp                  -6.0464608197
## log.nugget.V2.exp               -13.1184042697
## nu.log.range.exp                 15.0000000000
## nu.log.sill.exp                  -3.8020783365
## nu.log.nugget.(Intercept).exp    -5.6793527770
## 
## Function value(s):
## [1] 1314.749 1530.568 1530.568 1530.537 1529.040 1530.562 1530.562

7.4.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.2.4 <- createCV(denver.model.2.4, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.2.4 <- sapply(split(denver.model.2.4$obs$ID, Ind.cv.2.4), unique)
print(sapply(ID.cv.2.4, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.2.4)
## Ind.cv.2.4
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.2.4 <- apply(sapply(ID.cv.2.4,function(x) denver.model.2.4$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.2.4) <- denver.model.2.4$locations$ID
print(I.col.2.4)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.2.4$locations$long,
     denver.model.2.4$locations$lat,
     pch=23+floor(I.col.2.4/max(I.col.2.4)+.5), bg=I.col.2.4,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.2.4.cv <- coef(est.denver.model.2.4, pars="cov")[,c("par","init")]
x.init.2.4.cv

Run the model with cross validation.

est.denver.2.4.cv <- estimateCV(denver.model.2.4, x.init.2.4.cv, Ind.cv.2.4)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1392.2  |proj g|=       2.0609
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1392.829201 
## stopped after 7 iterations
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1125.7  |proj g|=           10
## At iterate    10  f =      -1384.2  |proj g|=        11.331
## At iterate    20  f =        -1392  |proj g|=        5.7371
## At iterate    30  f =      -1392.6  |proj g|=       0.27447
## At iterate    40  f =      -1392.7  |proj g|=        1.7114
## At iterate    50  f =      -1392.8  |proj g|=       0.11104
## At iterate    60  f =      -1392.8  |proj g|=       0.17282
## At iterate    70  f =      -1392.8  |proj g|=        0.0478
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1392.828770 
## stopped after 78 iterations
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=        -1399  |proj g|=        2.736
## At iterate    10  f =      -1399.1  |proj g|=       0.03185
## 
## iterations 11
## function evaluations 20
## segments explored during Cauchy searches 11
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.0318502
## final function value -1399.11
## 
## F = -1399.11
## final  value -1399.111391 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1133.9  |proj g|=           10
## At iterate    10  f =        -1346  |proj g|=        9.2472
## At iterate    20  f =      -1385.9  |proj g|=       0.40045
## At iterate    30  f =      -1397.1  |proj g|=        8.2906
## At iterate    40  f =      -1397.6  |proj g|=         2.643
## At iterate    50  f =      -1398.4  |proj g|=         1.816
## At iterate    60  f =      -1398.9  |proj g|=       0.52174
## At iterate    70  f =      -1399.1  |proj g|=       0.18871
## At iterate    80  f =      -1399.1  |proj g|=      0.027495
## 
## iterations 83
## function evaluations 118
## segments explored during Cauchy searches 86
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0315239
## final function value -1399.11
## 
## F = -1399.11
## final  value -1399.110586 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1402.7  |proj g|=       2.6825
## At iterate    10  f =      -1403.3  |proj g|=       0.18478
## 
## iterations 19
## function evaluations 26
## segments explored during Cauchy searches 19
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.00412731
## final function value -1403.28
## 
## F = -1403.28
## final  value -1403.277188 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1136.2  |proj g|=           10
## At iterate    10  f =      -1391.7  |proj g|=        11.589
## At iterate    20  f =        -1402  |proj g|=        1.8266
## At iterate    30  f =        -1403  |proj g|=       0.46681
## At iterate    40  f =      -1403.2  |proj g|=        1.1763
## At iterate    50  f =      -1403.3  |proj g|=      0.024271
## 
## iterations 56
## function evaluations 77
## segments explored during Cauchy searches 59
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0451103
## final function value -1403.28
## 
## F = -1403.28
## l(0) > u(0).  No feasible solutionfinal  value -1403.275455 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1366.2  |proj g|=       1.6004
## At iterate    10  f =      -1366.8  |proj g|=        4.0269
## At iterate    20  f =      -1367.3  |proj g|=     0.0015198
## 
## iterations 20
## function evaluations 27
## segments explored during Cauchy searches 21
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00151976
## final function value -1367.33
## 
## F = -1367.33
## final  value -1367.334074 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1107.3  |proj g|=           10
## At iterate    10  f =      -1357.8  |proj g|=        8.0515
## At iterate    20  f =      -1365.7  |proj g|=         1.172
## At iterate    30  f =      -1366.5  |proj g|=        2.6245
## At iterate    40  f =      -1367.1  |proj g|=        0.5499
## At iterate    50  f =      -1367.3  |proj g|=        1.1519
## At iterate    60  f =      -1367.3  |proj g|=      0.041379
## 
## iterations 61
## function evaluations 78
## segments explored during Cauchy searches 64
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0397386
## final function value -1367.33
## 
## F = -1367.33
## final  value -1367.328403 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1378.7  |proj g|=       8.1963
## At iterate    10  f =      -1379.4  |proj g|=       0.27516
## 
## iterations 19
## function evaluations 22
## segments explored during Cauchy searches 19
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.0222785
## final function value -1379.39
## 
## F = -1379.39
## final  value -1379.386720 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1119.2  |proj g|=           10
## At iterate    10  f =      -1369.1  |proj g|=        11.555
## At iterate    20  f =      -1377.7  |proj g|=        4.7751
## At iterate    30  f =      -1379.1  |proj g|=        0.2793
## At iterate    40  f =      -1379.2  |proj g|=        1.1839
## At iterate    50  f =      -1379.4  |proj g|=       0.18601
## At iterate    60  f =      -1379.4  |proj g|=       0.10862
## 
## iterations 64
## function evaluations 76
## segments explored during Cauchy searches 67
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00419073
## final function value -1379.39
## 
## F = -1379.39
## final  value -1379.385104 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1413.9  |proj g|=       5.6513
## At iterate    10  f =        -1414  |proj g|=       0.15656
## 
## iterations 15
## function evaluations 27
## segments explored during Cauchy searches 15
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.0125394
## final function value -1413.98
## 
## F = -1413.98
## final  value -1413.984515 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1147.7  |proj g|=           10
## At iterate    10  f =        -1403  |proj g|=        11.462
## At iterate    20  f =      -1413.1  |proj g|=        1.0258
## At iterate    30  f =      -1413.6  |proj g|=        1.6353
## At iterate    40  f =      -1413.8  |proj g|=        1.0381
## At iterate    50  f =      -1413.9  |proj g|=       0.88146
## At iterate    60  f =        -1414  |proj g|=       0.17752
## 
## iterations 65
## function evaluations 82
## segments explored during Cauchy searches 68
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0127687
## final function value -1413.98
## 
## F = -1413.98
## final  value -1413.982725 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1404.7  |proj g|=       4.6237
## At iterate    10  f =      -1405.3  |proj g|=      0.077518
## At iterate    20  f =      -1405.3  |proj g|=      0.026471
## 
## iterations 20
## function evaluations 25
## segments explored during Cauchy searches 20
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0264706
## final function value -1405.29
## 
## F = -1405.29
## final  value -1405.292583 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1140.4  |proj g|=           10
## At iterate    10  f =      -1394.5  |proj g|=        11.301
## At iterate    20  f =      -1404.7  |proj g|=       0.35974
## At iterate    30  f =        -1405  |proj g|=        0.9994
## At iterate    40  f =      -1405.2  |proj g|=       0.75316
## 
## iterations 48
## function evaluations 62
## segments explored during Cauchy searches 51
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0066031
## final function value -1405.29
## 
## F = -1405.29
## final  value -1405.285688 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1400.1  |proj g|=        2.982
## At iterate    10  f =      -1400.2  |proj g|=      0.090958
## 
## iterations 17
## function evaluations 38
## segments explored during Cauchy searches 17
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.00297838
## final function value -1400.21
## 
## F = -1400.21
## l(0) > u(0).  No feasible solutionfinal  value -1400.206042 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1130.3  |proj g|=           10
## At iterate    10  f =      -1392.2  |proj g|=        1.9394
## At iterate    20  f =      -1399.8  |proj g|=        3.5924
## At iterate    30  f =        -1400  |proj g|=       0.41188
## At iterate    40  f =      -1400.1  |proj g|=        0.3527
## At iterate    50  f =      -1400.2  |proj g|=       0.27516
## 
## iterations 56
## function evaluations 78
## segments explored during Cauchy searches 59
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00948687
## final function value -1400.21
## 
## F = -1400.21
## l(0) > u(0).  No feasible solutionfinal  value -1400.205072 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1402.5  |proj g|=       4.8141
## At iterate    10  f =      -1402.7  |proj g|=       0.26558
## At iterate    20  f =      -1402.7  |proj g|=     0.0051326
## 
## iterations 21
## function evaluations 26
## segments explored during Cauchy searches 22
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.00241763
## final function value -1402.68
## 
## F = -1402.68
## final  value -1402.681638 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1136.4  |proj g|=           10
## At iterate    10  f =      -1376.6  |proj g|=        20.647
## At iterate    20  f =      -1400.3  |proj g|=        1.3476
## At iterate    30  f =        -1402  |proj g|=        5.5393
## At iterate    40  f =      -1402.4  |proj g|=       0.41985
## At iterate    50  f =      -1402.6  |proj g|=       0.84706
## At iterate    60  f =      -1402.7  |proj g|=       0.17068
## 
## iterations 68
## function evaluations 83
## segments explored during Cauchy searches 71
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0157231
## final function value -1402.68
## 
## F = -1402.68
## final  value -1402.678306 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 4 variables are exactly at the bounds
## At iterate     0  f=      -1390.7  |proj g|=       1.0968
## At iterate    10  f =      -1391.5  |proj g|=       0.96263
## 
## iterations 16
## function evaluations 22
## segments explored during Cauchy searches 17
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.00175074
## final function value -1391.5
## 
## F = -1391.5
## final  value -1391.500816 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1128.5  |proj g|=           10
## At iterate    10  f =        -1372  |proj g|=        2.5389
## At iterate    20  f =      -1388.8  |proj g|=        1.8486
## At iterate    30  f =      -1390.7  |proj g|=       0.38459
## At iterate    40  f =      -1391.3  |proj g|=        1.0385
## At iterate    50  f =      -1391.5  |proj g|=        1.0077
## At iterate    60  f =      -1391.5  |proj g|=       0.24024
## 
## iterations 67
## function evaluations 91
## segments explored during Cauchy searches 70
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0391954
## final function value -1391.49
## 
## F = -1391.49
## final  value -1391.492099 
## converged
## 
print(est.denver.2.4.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 7 converged, 3 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv      eigen.min eigen.all.min
## 1  1392.829       FALSE FALSE -0.00017304362            NA
## 2  1399.111        TRUE  TRUE  0.00008853290            NA
## 3  1403.275        TRUE  TRUE  0.00011134531            NA
## 4  1367.328        TRUE  TRUE  0.00001422906            NA
## 5  1379.387        TRUE FALSE -0.00009925873            NA
## 6  1413.985        TRUE  TRUE  0.00002587899            NA
## 7  1405.293        TRUE  TRUE  0.00000468744            NA
## 8  1400.206        TRUE FALSE -0.00020909296            NA
## 9  1402.678        TRUE  TRUE  0.00006727105            NA
## 10 1391.492        TRUE  TRUE  0.00012279444            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.2.4, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.2.4.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.2, denver.model.2.4, est.denver.model.2.4, est.denver.2.4.cv,
     file = here::here("Results", "Denver_ST_Model_2.4.rdata"))

7.4.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.2.4.cv <- predictCV(denver.model.2.4, est.denver.2.4.cv, LTA = T)
pred.2.4.cv.log <- predictCV(denver.model.2.4, est.denver.2.4.cv,
                             LTA = T, transform="unbiased")

names(pred.2.4.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.2.4.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.12082381 0.12250315 0.09452486
## average 0.07485986 0.07660021 0.06475139
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6562331  0.6466106 0.7895974
## average 0.7545543  0.7430093 0.8163649
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9124797
## average 0.9000000
summary(pred.2.4.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.14459025 0.14639863 0.10887024 0.10903983
## average 0.08583682 0.08759418 0.07223326 0.07260243
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6762783  0.6681302 0.8164678 0.8158956
## average 0.8017541  0.7935536 0.8596116 0.8581729
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9124797
## average 0.9166667
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.4.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.4.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod2.4.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.2.4.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.2.4.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

7.5 Model 2.5: Smoothing for beta fields and error term

7.5.1 Create the model object (exp covariance structure)

Now I’m using the exp covariance structure for cov.beta and cov.nu.

names(denver.data2.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR2.5<- list(covar_fun, covar_fun, covar_fun)

cov.beta2.5 <-  list(covf=c("exp", "exp", "exp"), nugget = c(TRUE, TRUE, TRUE))
cov.nu2.5 <- list(covf="exp", nugget = T, random.effect = FALSE)
locations2.5 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.2.5 <- createSTmodel(denver.data2.2, LUR = LUR2.5,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta2.5, cov.nu = cov.nu2.5,
                                  locations = locations2.5)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.2.5
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): exp, exp, exp 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

7.5.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.2.5, all=FALSE)
names
##  [1] "log.range.const.exp"           "log.sill.const.exp"           
##  [3] "log.nugget.const.exp"          "log.range.V1.exp"             
##  [5] "log.sill.V1.exp"               "log.nugget.V1.exp"            
##  [7] "log.range.V2.exp"              "log.sill.V2.exp"              
##  [9] "log.nugget.V2.exp"             "nu.log.range.exp"             
## [11] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# x.init.2.5 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
#                     c(0, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, -1),
#                     c(0, -1, -5, 0, -1, -5, 0, -1, -5, 0, -1, -5),
#                     c(0, -5, -1, 0, -5, -1, 0, -1, -1, 0, -1, -1),
#                     c(0, -5, -5, 0, -5, -5, 0, -1, -5, 0, -1, -5),
#                     c(2, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1),
#                     c(2, -1, -5, 2, -1, -5, 2, -1, -5, 2, -1, -5),
#                     c(2, -5, -1, 2, -5, -1, 2, -1, -1, 2, -1, -1),
#                     c(2, -5, -5, 2, -5, -5, 2, -1, -5, 2, -1, -5),
#                     c(4, -1, -1, 4, -1, -1, 4, -1, -1, 4, -1, -1),
#                     c(4, -1, -5, 4, -1, -5, 4, -1, -5, 4, -1, -5),
#                     c(4, -5, -1, 4, -5, -1, 4, -1, -1, 4, -1, -1),
#                     c(4, -5, -5, 4, -5, -5, 4, -1, -5, 4, -1, -5),
#                     c(6, -1, -1, 6, -1, -1, 6, -1, -1, 6, -1, -1),
#                     c(6, -1, -5, 6, -1, -5, 6, -1, -5, 6, -1, -5),
#                     c(6, -5, -1, 6, -5, -1, 6, -1, -1, 6, -1, -1),
#                     c(6, -5, -5, 6, -5, -5, 6, -1, -5, 6, -1, -5)
#                     )

x.init.2.5 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                    c(6, -5, -1, 6, -5, -1, 6, -1, -1, 6, -1, -1),
                    c(6, -5, -5, 6, -5, -5, 6, -5, -10, 10, -5, -5),
                    c(6, -10, -1, 6, -10, -1, 6, -1, -1, 6, -1, -1),
                    c(6, -10, -5, 6, -10, -5, 6, -5, -5, 6, -5, -5))

rownames(x.init.2.5) <- loglikeSTnames(denver.model.2.5, all=FALSE)
x.init.2.5
##                               [,1] [,2] [,3] [,4] [,5]
## log.range.const.exp              0    6    6    6    6
## log.sill.const.exp               0   -5   -5  -10  -10
## log.nugget.const.exp             0   -1   -5   -1   -5
## log.range.V1.exp                 0    6    6    6    6
## log.sill.V1.exp                  0   -5   -5  -10  -10
## log.nugget.V1.exp                0   -1   -5   -1   -5
## log.range.V2.exp                 0    6    6    6    6
## log.sill.V2.exp                  0   -1   -5   -1   -5
## log.nugget.V2.exp                0   -1  -10   -1   -5
## nu.log.range.exp                 0    6   10    6    6
## nu.log.sill.exp                  0   -1   -5   -1   -5
## nu.log.nugget.(Intercept).exp    0   -1   -5   -1   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.2.5 <- estimate.STmodel(denver.model.2.5, x.init.2.5)
## Optimisation using starting value 1/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       405.46  |proj g|=           15
## At iterate    10  f =      -1313.3  |proj g|=        1.6165
## At iterate    20  f =        -1314  |proj g|=        7.1596
## At iterate    30  f =      -1314.7  |proj g|=      0.045611
## At iterate    40  f =      -1314.7  |proj g|=       0.51191
## At iterate    50  f =      -1314.8  |proj g|=      0.014321
## 
## iterations 52
## function evaluations 76
## segments explored during Cauchy searches 54
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.02927
## final function value -1314.75
## 
## F = -1314.75
## l(0) > u(0).  No feasible solutionfinal  value -1314.752720 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       0.5573  |proj g|=           14
## At iterate    10  f =      -1506.8  |proj g|=        7.0917
## At iterate    20  f =      -1514.3  |proj g|=       0.40777
## At iterate    30  f =        -1515  |proj g|=        2.3434
## ys=-1.554e-02  -gs= 1.466e-01, BFGS update SKIPPED
## At iterate    40  f =      -1529.3  |proj g|=        1.1433
## At iterate    50  f =      -1529.5  |proj g|=        1.6974
## At iterate    60  f =      -1529.6  |proj g|=      0.027368
## 
## iterations 69
## function evaluations 100
## segments explored during Cauchy searches 73
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0115813
## final function value -1529.57
## 
## F = -1529.57
## l(0) > u(0).  No feasible solutionfinal  value -1529.571031 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 3/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1346.4  |proj g|=           10
## At iterate    10  f =      -1526.2  |proj g|=        20.783
## At iterate    20  f =      -1530.3  |proj g|=        3.1211
## At iterate    30  f =      -1530.5  |proj g|=        2.0195
## At iterate    40  f =      -1530.5  |proj g|=       0.33502
## At iterate    50  f =      -1530.6  |proj g|=       0.13647
## 
## iterations 55
## function evaluations 65
## segments explored during Cauchy searches 57
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0345978
## final function value -1530.56
## 
## F = -1530.56
## final  value -1530.563425 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      0.02747  |proj g|=           14
## At iterate    10  f =      -1484.3  |proj g|=        11.365
## At iterate    20  f =      -1521.7  |proj g|=        11.453
## At iterate    30  f =      -1529.4  |proj g|=       0.19199
## At iterate    40  f =      -1529.5  |proj g|=       0.11691
## At iterate    50  f =      -1529.6  |proj g|=       0.19925
## At iterate    60  f =      -1529.6  |proj g|=      0.025061
## At iterate    70  f =      -1529.6  |proj g|=       0.15748
## 
## iterations 77
## function evaluations 93
## segments explored during Cauchy searches 81
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0228155
## final function value -1529.57
## 
## F = -1529.57
## final  value -1529.571549 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 5/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1246.8  |proj g|=           10
## At iterate    10  f =      -1477.8  |proj g|=         20.23
## At iterate    20  f =      -1521.9  |proj g|=        11.634
## At iterate    30  f =      -1529.5  |proj g|=       0.25847
## At iterate    40  f =      -1529.5  |proj g|=       0.24357
## At iterate    50  f =      -1529.5  |proj g|=      0.076312
## At iterate    60  f =      -1529.6  |proj g|=      0.090303
## At iterate    70  f =      -1529.6  |proj g|=      0.033266
## 
## iterations 79
## function evaluations 110
## segments explored during Cauchy searches 83
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0311324
## final function value -1529.57
## 
## F = -1529.57
## l(0) > u(0).  No feasible solutionfinal  value -1529.571105 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
print(est.denver.model.2.5)
## Optimisation for STmodel with 5 starting points.
##   Results: 0 converged, 5 not converged, 0 failed.
##   Best result for starting point 3, optimisation has NOT converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                            [,1]            [,2]           [,3]
## gamma.bc_st_no2                   0.01671348871   0.01875775180   0.0188437900
## alpha.const.(Intercept)          -0.00231782184  -0.01011034344  -0.0150908953
## alpha.const.impervious_2500       0.05109114092   0.06463573330   0.0647379451
## alpha.const.open_2500             0.01641658135   0.02894249671   0.0290009131
## alpha.const.low_int_100           0.00772197911   0.02063143737   0.0207625655
## alpha.const.med_int_50            0.00684192499  -0.00545245152  -0.0054059934
## alpha.const.high_int_50           0.01707914082   0.00558227585   0.0059519574
## alpha.const.high_int_100         -0.02293332741  -0.00008394259  -0.0005346953
## alpha.const.ag_250               -0.00414733492  -0.00128931458  -0.0013452091
## alpha.const.pop_den_50            0.00541204891   0.00274338367   0.0025368302
## alpha.const.dist_m_compost        0.00555077578   0.00041304266   0.0002962753
## alpha.const.dist_m_military       0.01843808646   0.00655683438   0.0063478506
## alpha.const.len_m_highways_2500  -0.00009758115   0.00535502364   0.0051881467
## alpha.const.aadt_100              0.03587019169   0.02152544132   0.0223284366
## alpha.const.aadt_2500            -0.00026251779  -0.01011678195  -0.0100954868
## alpha.V1.(Intercept)             -0.28330310459  -0.28625389720  -0.2863759238
## alpha.V1.impervious_2500         -0.05399078413  -0.05850945456  -0.0568203458
## alpha.V1.open_2500               -0.04291033973  -0.03925860150  -0.0381278111
## alpha.V1.low_int_100             -0.00094451882  -0.00806129833  -0.0074434776
## alpha.V1.med_int_50              -0.00615636965  -0.00539891574  -0.0047357040
## alpha.V1.high_int_50              0.01363378919  -0.00317650918  -0.0002910233
## alpha.V1.high_int_100            -0.04140069641  -0.00903209327  -0.0129823807
## alpha.V1.ag_250                  -0.01147148304   0.01346329399   0.0130680027
## alpha.V1.pop_den_50              -0.01639753814  -0.00091734751  -0.0027133057
## alpha.V1.dist_m_compost          -0.02753453685  -0.00353224898  -0.0045381256
## alpha.V1.dist_m_military         -0.01381279357   0.00884697961   0.0076465286
## alpha.V1.len_m_highways_2500      0.00584046803   0.01291995523   0.0122277472
## alpha.V1.aadt_100                 0.02131065166   0.01173096332   0.0186807534
## alpha.V1.aadt_2500                0.00613901757   0.01404673786   0.0142000600
## alpha.V2.(Intercept)             -0.18450280529  -0.10016066154  -0.1094618578
## alpha.V2.impervious_2500         -0.01096872569  -0.00494680891  -0.0030152809
## alpha.V2.open_2500                0.01085114121   0.02027005634   0.0217889894
## alpha.V2.low_int_100              0.00107236443   0.00422713107   0.0052313526
## alpha.V2.med_int_50              -0.00082882328  -0.01512669860  -0.0144879825
## alpha.V2.high_int_50             -0.00207388108  -0.03400095786  -0.0304042371
## alpha.V2.high_int_100            -0.04918757762   0.01814762022   0.0136790264
## alpha.V2.ag_250                  -0.03059563519  -0.00241478489  -0.0027370732
## alpha.V2.pop_den_50              -0.00059982148   0.00892684284   0.0069999318
## alpha.V2.dist_m_compost           0.00477176035   0.02763209806   0.0263914972
## alpha.V2.dist_m_military          0.01142614029   0.02880643136   0.0273514159
## alpha.V2.len_m_highways_2500      0.01242533177   0.02382412950   0.0227454425
## alpha.V2.aadt_100                 0.01312528550  -0.02422428720  -0.0169529302
## alpha.V2.aadt_2500               -0.00374730951  -0.00121620112  -0.0009884244
## log.range.const.exp               0.00000000000   6.86717889675   6.1421142234
## log.sill.const.exp              -15.00000000000 -15.00000000000 -15.0000000000
## log.nugget.const.exp            -15.00000000000 -15.00000000000 -15.0000000000
## log.range.V1.exp                  0.00000000000  -0.85818626299   3.5001378405
## log.sill.V1.exp                 -15.00000000000  -6.62033729508 -14.9884204900
## log.nugget.V1.exp                -8.68779998044 -14.55450979942  -6.6024556692
## log.range.V2.exp                  0.00000000000   6.39650342773   6.3884473166
## log.sill.V2.exp                 -14.58754374522  -6.24952881687  -6.0480167523
## log.nugget.V2.exp                -7.50766194541  -7.69806176447 -13.8639697684
## nu.log.range.exp                  0.00000000000  15.00000000000  15.0000000000
## nu.log.sill.exp                  -5.94425033413  -3.79783457203  -3.8027578091
## nu.log.nugget.(Intercept).exp    -4.69355054864  -5.67647781453  -5.6795003627
##                                            [,4]            [,5]
## gamma.bc_st_no2                   0.01875530343   0.01875848488
## alpha.const.(Intercept)          -0.01004813669  -0.01012758708
## alpha.const.impervious_2500       0.06463634752   0.06463498274
## alpha.const.open_2500             0.02894298209   0.02894220994
## alpha.const.low_int_100           0.02063190354   0.02063051427
## alpha.const.med_int_50           -0.00545352437  -0.00545122208
## alpha.const.high_int_50           0.00558111129   0.00558186769
## alpha.const.high_int_100         -0.00008108417  -0.00008386925
## alpha.const.ag_250               -0.00128962667  -0.00128943636
## alpha.const.pop_den_50            0.00274196540   0.00274351320
## alpha.const.dist_m_compost        0.00041312737   0.00041334248
## alpha.const.dist_m_military       0.00655670650   0.00655714122
## alpha.const.len_m_highways_2500   0.00535647088   0.00535553823
## alpha.const.aadt_100              0.02152479684   0.02152480229
## alpha.const.aadt_2500            -0.01011743581  -0.01011738646
## alpha.V1.(Intercept)             -0.28622947173  -0.28624705425
## alpha.V1.impervious_2500         -0.05850915773  -0.05850345355
## alpha.V1.open_2500               -0.03925903905  -0.03925546946
## alpha.V1.low_int_100             -0.00806203935  -0.00806266808
## alpha.V1.med_int_50              -0.00539832636  -0.00539627873
## alpha.V1.high_int_50             -0.00317768577  -0.00317552043
## alpha.V1.high_int_100            -0.00902954558  -0.00903759368
## alpha.V1.ag_250                   0.01346172658   0.01346169355
## alpha.V1.pop_den_50              -0.00091786875  -0.00091781280
## alpha.V1.dist_m_compost          -0.00353138888  -0.00353058640
## alpha.V1.dist_m_military          0.00884799731   0.00884939860
## alpha.V1.len_m_highways_2500      0.01291972816   0.01291821357
## alpha.V1.aadt_100                 0.01172899854   0.01173135422
## alpha.V1.aadt_2500                0.01404678081   0.01404680527
## alpha.V2.(Intercept)             -0.10006279900  -0.10014879963
## alpha.V2.impervious_2500         -0.00495059285  -0.00494755603
## alpha.V2.open_2500                0.02026303287   0.02026537852
## alpha.V2.low_int_100              0.00421983233   0.00421955385
## alpha.V2.med_int_50              -0.01512562239  -0.01512403593
## alpha.V2.high_int_50             -0.03399719739  -0.03400141039
## alpha.V2.high_int_100             0.01814012810   0.01813917270
## alpha.V2.ag_250                  -0.00242003686  -0.00242113709
## alpha.V2.pop_den_50               0.00892369241   0.00892747436
## alpha.V2.dist_m_compost           0.02763166874   0.02763581091
## alpha.V2.dist_m_military          0.02880714838   0.02880760256
## alpha.V2.len_m_highways_2500      0.02382858794   0.02382763718
## alpha.V2.aadt_100                -0.02422239581  -0.02422229997
## alpha.V2.aadt_2500               -0.00122077722  -0.00122182447
## log.range.const.exp               6.46656249639   6.25229874502
## log.sill.const.exp              -15.00000000000 -15.00000000000
## log.nugget.const.exp            -15.00000000000 -15.00000000000
## log.range.V1.exp                  1.29114923534   3.20507045600
## log.sill.V1.exp                  -6.62072164441  -6.62059804812
## log.nugget.V1.exp               -13.86882114689 -14.31484298590
## log.range.V2.exp                  6.39111256064   6.39290071859
## log.sill.V2.exp                  -6.24670750133  -6.25047796810
## log.nugget.V2.exp                -7.70962744124  -7.70028039509
## nu.log.range.exp                 15.00000000000  15.00000000000
## nu.log.sill.exp                  -3.79745259035  -3.79784949015
## nu.log.nugget.(Intercept).exp    -5.67651997817  -5.67634171405
## 
## Function value(s):
## [1] 1314.753 1529.571 1530.563 1529.572 1529.571

7.5.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.2.5 <- createCV(denver.model.2.5, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.2.5 <- sapply(split(denver.model.2.5$obs$ID, Ind.cv.2.5), unique)
print(sapply(ID.cv.2.5, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.2.5)
## Ind.cv.2.5
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.2.5 <- apply(sapply(ID.cv.2.5,function(x) denver.model.2.5$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.2.5) <- denver.model.2.5$locations$ID
print(I.col.2.5)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.2.5$locations$long,
     denver.model.2.5$locations$lat,
     pch=23+floor(I.col.2.5/max(I.col.2.5)+.5), bg=I.col.2.5,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.2.5.cv <- coef(est.denver.model.2.5, pars="cov")[,c("par","init")]
x.init.2.5.cv

Run the model with cross validation.

Note: I got the following error when trying to run the CV:

Error in solve.default(res[[i]]$hessian) : Lapack routine dgesv: system is exactly singular: U[4,4] = 0

# est.denver.2.5.cv <- estimateCV(denver.model.2.5, x.init.2.5.cv, Ind.cv.2.5)
# print(est.denver.2.5.cv)
# 
# par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
# with(coef(est.denver.model.2.5, pars="all"),
#      plotCI((1:length(par))+.3, par, uiw=1.96*sd,
#             col=2, xlab="", xaxt="n", ylab=""))
# boxplot(est.denver.2.5.cv, "all", boxwex=.4, col="grey", add=TRUE)
# 
# #' Save the results as an .rdata object
# save(denver.data2.2, denver.model.2.5, est.denver.model.2.5, est.denver.2.5.cv,
#      file = here::here("Results", "Denver_ST_Model_2.5.rdata"))

7.5.4 Prediction using the CV model

I didn’t make predictions with the CV model since it wasn’t successfully implemented

# pred.2.5.cv <- predictCV(denver.model.2.5, est.denver.2.5.cv, LTA = T)
# pred.2.5.cv.log <- predictCV(denver.model.2.5, est.denver.2.5.cv,
#                              LTA = T, transform="unbiased")
# 
# names(pred.2.5.cv)
# summary(pred.2.5.cv)
# summary(pred.2.5.cv.log)
# 
# par(mfrow=c(1,2), mar=c(3.3,3.3,2.5,1), mgp=c(2,1,0))
# plot(pred.2.5.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
#      col=c("ID", "black", "grey"),
#      ylim=c(-1,2),
#      xlab="Observations", ylab="Predictions",
#      main="Cross-validation BC (log ug/m3)")
# with(pred.2.5.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
#                                       xlab="Observations", ylab="Predictions",
#                                       main="Temporal average BC (ug/m3)"))
# abline(0, 1, col="grey")
# 
# jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod2.5.jpeg"),
#      width = 8, height = 4, units = "in", res = 500)
# par(mfrow=c(1,2), mar=c(3.3,3.3,2.5,1), mgp=c(2,1,0))
# plot(pred.2.5.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
#      col=c("ID", "black", "grey"),
#      ylim=c(-1,2),
#      xlab="Observations", ylab="Predictions",
#      main="Cross-validation BC (log ug/m3)")
# with(pred.2.5.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
#                                       xlab="Observations", ylab="Predictions",
#                                       main="Temporal average BC (ug/m3)"))
# abline(0, 1, col="grey")
# dev.off()

8 Updated models (NO2 + BC, one basis function)

The models above were OK, but we were hitting the upper limit on a lot of the parameters. Here I though I would try going back to 1 basis function (just to see what happens). I know based on the plots above that using one basis function resulted in a good amount of residual autocorrelation. I’m mostly running these models for my own edification.

8.1 Model 3.1: simplest form

8.1.1 Create the model object

For this version of the model, use iid for both cov.beta (beta0 and beta1) and cov.nu (error term). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data2.1$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR3.1 <- list(covar_fun, covar_fun)

cov.beta3.1 <-  list(covf="iid", nugget = T)
cov.nu3.1 <- list(covf="iid", nugget = T, random.effect = FALSE)
locations3.1 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.3.1 <- createSTmodel(denver.data2.1, LUR = LUR3.1,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta3.1, cov.nu = cov.nu3.1,
                                  locations = locations3.1)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.3.1
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 1 basis function(s):
## [1] "V1"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, iid 
##  Nugget: Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: iid 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

8.1.2 Estimate model parameters

We want to try a number of initial conditions to make sure we find the “right” solution.

names <- loglikeSTnames(denver.model.3.1, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.nugget.V1.iid"            
## [3] "nu.log.nugget.(Intercept).iid"
# x.init.3.1 <- cbind(c(rep(-1, 3)), c(rep(-2, 3)), c(rep(-3, 3)),
#                     c(rep(-4, 3)), c(rep(-5, 3)), c(rep(-6, 3)))
# x.init.3.1[nrow(x.init.3.1),] <- 0

x.init.3.1 <- cbind(c(0, 0, 0),
                    c(-5, -10, -10),
                    c(-8, -8, -5),
                    c(-8, -5, -5))

rownames(x.init.3.1) <- loglikeSTnames(denver.model.3.1, all=FALSE)
x.init.3.1
##                               [,1] [,2] [,3] [,4]
## log.nugget.const.iid             0   -5   -8   -8
## log.nugget.V1.iid                0  -10   -8   -5
## nu.log.nugget.(Intercept).iid    0  -10   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.3.1 <- estimate.STmodel(denver.model.3.1, x.init.3.1)
## Optimisation using starting value 1/4
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       127.43  |proj g|=           15
## At iterate    10  f =      -1074.5  |proj g|=        1.5038
## At iterate    20  f =      -1074.7  |proj g|=     0.0021223
## At iterate    30  f =      -1074.8  |proj g|=       0.11534
## 
## iterations 32
## function evaluations 60
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0113148
## final function value -1074.77
## 
## F = -1074.77
## l(0) > u(0).  No feasible solutionfinal  value -1074.766566 
## converged
## Optimisation using starting value 2/4
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=   1.6769e+05  |proj g|=           25
## At iterate    10  f =      -1074.7  |proj g|=       0.77513
## 
## iterations 17
## function evaluations 23
## segments explored during Cauchy searches 19
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.000643445
## final function value -1074.73
## 
## F = -1074.73
## final  value -1074.728547 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/4
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -664.02  |proj g|=           20
## At iterate    10  f =      -1074.4  |proj g|=        3.0789
## At iterate    20  f =      -1074.8  |proj g|=      0.023187
## 
## iterations 23
## function evaluations 47
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.000174318
## final function value -1074.77
## 
## F = -1074.77
## l(0) > u(0).  No feasible solutionfinal  value -1074.766562 
## converged
## Optimisation using starting value 4/4
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -649.69  |proj g|=           20
## At iterate    10  f =      -1074.6  |proj g|=        1.2306
## At iterate    20  f =      -1074.8  |proj g|=        1.1495
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 24
## function evaluations 68
## segments explored during Cauchy searches 27
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0389043
## final function value -1074.77
## 
## F = -1074.77
## l(0) > u(0).  No feasible solutionfinal  value -1074.766584 
## converged
print(est.denver.model.3.1)
## Optimisation for STmodel with 4 starting points.
##   Results: 3 converged, 1 not converged, 0 failed.
##   Best result for starting point 4, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                          [,1]           [,2]          [,3]
## gamma.bc_st_no2                   0.010443471   0.0103919617   0.010443426
## alpha.const.(Intercept)           0.183446181   0.1845955602   0.183447177
## alpha.const.impervious_2500       0.007284776   0.0066053656   0.007284191
## alpha.const.open_2500            -0.011459206  -0.0118738388  -0.011459556
## alpha.const.low_int_100           0.023547082   0.0230599930   0.023546660
## alpha.const.med_int_50            0.021780235   0.0220990925   0.021780517
## alpha.const.high_int_50           0.007685997   0.0074753699   0.007685809
## alpha.const.high_int_100          0.012483030   0.0128184652   0.012483329
## alpha.const.ag_250                0.003087174   0.0031494802   0.003087227
## alpha.const.pop_den_50            0.005176938   0.0053568626   0.005177096
## alpha.const.dist_m_compost        0.007594693   0.0077275503   0.007594811
## alpha.const.dist_m_military       0.011885435   0.0119686446   0.011885511
## alpha.const.len_m_highways_2500  -0.012589400  -0.0123620229  -0.012589197
## alpha.const.aadt_100              0.021010805   0.0208311554   0.021010644
## alpha.const.aadt_2500             0.005561657   0.0057211964   0.005561793
## alpha.V1.(Intercept)             -0.194900133  -0.1954977883  -0.194900659
## alpha.V1.impervious_2500         -0.011601483  -0.0113306129  -0.011601251
## alpha.V1.open_2500               -0.026366384  -0.0263002810  -0.026366335
## alpha.V1.low_int_100             -0.014035747  -0.0136486884  -0.014035410
## alpha.V1.med_int_50              -0.018197144  -0.0185072015  -0.018197419
## alpha.V1.high_int_50             -0.002969003  -0.0028176357  -0.002968866
## alpha.V1.high_int_100             0.004029048   0.0037803226   0.004028823
## alpha.V1.ag_250                   0.008636394   0.0082476182   0.008636056
## alpha.V1.pop_den_50              -0.015081757  -0.0152406615  -0.015081899
## alpha.V1.dist_m_compost          -0.021605158  -0.0220096882  -0.021605515
## alpha.V1.dist_m_military         -0.005943014  -0.0063855125  -0.005943406
## alpha.V1.len_m_highways_2500      0.007878868   0.0076969101   0.007878705
## alpha.V1.aadt_100                 0.021540602   0.0210460486   0.021540183
## alpha.V1.aadt_2500                0.001031038   0.0007527892   0.001030795
## log.nugget.const.iid            -15.000000000 -15.0000000000 -15.000000000
## log.nugget.V1.iid                -9.372768289 -14.2651044512  -9.373721609
## nu.log.nugget.(Intercept).iid    -3.790506426  -3.7848263138  -3.790530678
##                                          [,4]
## gamma.bc_st_no2                   0.010442858
## alpha.const.(Intercept)           0.183459876
## alpha.const.impervious_2500       0.007276730
## alpha.const.open_2500            -0.011464019
## alpha.const.low_int_100           0.023541276
## alpha.const.med_int_50            0.021784118
## alpha.const.high_int_50           0.007683409
## alpha.const.high_int_100          0.012487146
## alpha.const.ag_250                0.003087903
## alpha.const.pop_den_50            0.005179111
## alpha.const.dist_m_compost        0.007596311
## alpha.const.dist_m_military       0.011886480
## alpha.const.len_m_highways_2500  -0.012586622
## alpha.const.aadt_100              0.021008599
## alpha.const.aadt_2500             0.005563532
## alpha.V1.(Intercept)             -0.194907361
## alpha.V1.impervious_2500         -0.011598292
## alpha.V1.open_2500               -0.026365710
## alpha.V1.low_int_100             -0.014031120
## alpha.V1.med_int_50              -0.018200921
## alpha.V1.high_int_50             -0.002967129
## alpha.V1.high_int_100             0.004025959
## alpha.V1.ag_250                   0.008631740
## alpha.V1.pop_den_50              -0.015083715
## alpha.V1.dist_m_compost          -0.021610062
## alpha.V1.dist_m_military         -0.005948401
## alpha.V1.len_m_highways_2500      0.007876629
## alpha.V1.aadt_100                 0.021534831
## alpha.V1.aadt_2500                0.001027709
## log.nugget.const.iid            -15.000000000
## log.nugget.V1.iid                -9.385466714
## nu.log.nugget.(Intercept).iid    -3.790368943
## 
## Function value(s):
## [1] 1074.767 1074.729 1074.767 1074.767

8.1.3 Cross-validation

Define the CV groups (and don’t forget to set the seed here!)

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.3.1 <- createCV(denver.model.3.1, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.3.1 <- sapply(split(denver.model.3.1$obs$ID, Ind.cv.3.1), unique)
print(sapply(ID.cv.3.1, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.3.1)
## Ind.cv.3.1
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.3.1 <- apply(sapply(ID.cv.3.1,function(x) denver.model.3.1$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.3.1) <- denver.model.3.1$locations$ID
print(I.col.3.1)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.3.1$locations$long,
     denver.model.3.1$locations$lat,
     pch=23+floor(I.col.3.1/max(I.col.3.1)+.5), bg=I.col.3.1,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.3.1.cv <- coef(est.denver.model.3.1, pars="cov")[,c("par","init")]
x.init.3.1.cv

Run the model with cross validation.

est.denver.3.1.cv <- estimateCV(denver.model.3.1, x.init.3.1.cv, Ind.cv.3.1)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -973.74  |proj g|=       10.449
## 
## iterations 3
## function evaluations 10
## segments explored during Cauchy searches 3
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.157119
## final function value -973.901
## 
## F = -973.901
## final  value -973.901104 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -563.93  |proj g|=           20
## At iterate    10  f =      -973.72  |proj g|=       0.17434
## At iterate    20  f =      -973.91  |proj g|=      0.021524
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -973.906428 
## stopped after 20 iterations
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=       -977.1  |proj g|=        12.94
## At iterate    10  f =      -977.57  |proj g|=       0.77781
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -977.606731 
## stopped after 17 iterations
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -547.23  |proj g|=           20
## At iterate    10  f =       -977.3  |proj g|=       0.25054
## At iterate    20  f =      -977.61  |proj g|=     0.0010744
## 
## iterations 20
## function evaluations 27
## segments explored during Cauchy searches 22
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00107445
## final function value -977.607
## 
## F = -977.607
## final  value -977.606622 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=       -983.8  |proj g|=       9.1949
## At iterate    10  f =      -984.26  |proj g|=        0.9396
## 
## iterations 18
## function evaluations 30
## segments explored during Cauchy searches 18
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0134243
## final function value -984.307
## 
## F = -984.307
## final  value -984.306871 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -553.66  |proj g|=           20
## At iterate    10  f =         -984  |proj g|=       0.27613
## At iterate    20  f =      -984.31  |proj g|=     9.346e-05
## 
## iterations 21
## function evaluations 29
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 1.35992e-06
## final function value -984.307
## 
## F = -984.307
## final  value -984.306864 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -948.03  |proj g|=        18.79
## 
## iterations 3
## function evaluations 8
## segments explored during Cauchy searches 4
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.139255
## final function value -948.721
## 
## F = -948.721
## final  value -948.720799 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -520.34  |proj g|=           20
## At iterate    10  f =      -948.53  |proj g|=        3.5394
## At iterate    20  f =      -948.64  |proj g|=      0.035535
## 
## iterations 20
## function evaluations 29
## segments explored during Cauchy searches 22
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 0
## norm of the final projected gradient 0.0355355
## final function value -948.644
## 
## F = -948.644
## final  value -948.644053 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=       -969.6  |proj g|=       11.976
## At iterate    10  f =      -969.89  |proj g|=       0.42942
## 
## iterations 19
## function evaluations 33
## segments explored during Cauchy searches 19
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00345587
## final function value -969.948
## 
## F = -969.948
## final  value -969.947654 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -550.64  |proj g|=           20
## At iterate    10  f =      -969.67  |proj g|=       0.17121
## 
## iterations 15
## function evaluations 33
## segments explored during Cauchy searches 17
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 0
## norm of the final projected gradient 0.0978028
## final function value -969.93
## 
## F = -969.93
## l(0) > u(0).  No feasible solutionfinal  value -969.929925 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -990.96  |proj g|=       12.642
## 
## iterations 3
## function evaluations 8
## segments explored during Cauchy searches 3
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.131972
## final function value -991.189
## 
## F = -991.189
## final  value -991.188804 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -565.88  |proj g|=           20
## At iterate    10  f =      -991.01  |proj g|=       0.58748
## At iterate    20  f =      -991.21  |proj g|=     0.0021602
## 
## iterations 22
## function evaluations 30
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00753794
## final function value -991.214
## 
## F = -991.214
## final  value -991.214219 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -987.17  |proj g|=       8.6697
## At iterate    10  f =      -987.73  |proj g|=        1.0246
## 
## iterations 17
## function evaluations 20
## segments explored during Cauchy searches 17
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 7.27027e-07
## final function value -987.761
## 
## F = -987.761
## final  value -987.761231 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -550.4  |proj g|=           20
## At iterate    10  f =      -987.47  |proj g|=       0.23737
## At iterate    20  f =      -987.76  |proj g|=    0.00027204
## 
## iterations 21
## function evaluations 30
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 2.60434e-06
## final function value -987.761
## 
## F = -987.761
## final  value -987.761231 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -978.32  |proj g|=       10.363
## At iterate    10  f =      -978.73  |proj g|=       0.35762
## 
## iterations 16
## function evaluations 32
## segments explored during Cauchy searches 16
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.106865
## final function value -978.757
## 
## F = -978.757
## l(0) > u(0).  No feasible solutionfinal  value -978.756900 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -556.67  |proj g|=           20
## At iterate    10  f =      -978.45  |proj g|=       0.16567
## At iterate    20  f =      -978.76  |proj g|=     0.0055499
## 
## iterations 22
## function evaluations 35
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 3.18551e-07
## final function value -978.757
## 
## F = -978.757
## final  value -978.757092 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -983.29  |proj g|=       13.405
## 
## iterations 2
## function evaluations 6
## segments explored during Cauchy searches 2
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.170049
## final function value -983.548
## 
## F = -983.548
## final  value -983.547576 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -560.98  |proj g|=           20
## At iterate    10  f =      -983.36  |proj g|=       0.61405
## At iterate    20  f =      -983.55  |proj g|=        0.0843
## 
## iterations 21
## function evaluations 37
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0842959
## final function value -983.549
## 
## F = -983.549
## l(0) > u(0).  No feasible solutionfinal  value -983.549422 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -978.73  |proj g|=       6.9099
## 
## iterations 3
## function evaluations 13
## segments explored during Cauchy searches 3
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.171989
## final function value -978.796
## 
## F = -978.796
## final  value -978.795924 
## converged
## 
## Optimisation using starting value 2/2
## N = 3, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -572.3  |proj g|=           20
## At iterate    10  f =      -978.65  |proj g|=        1.4816
## At iterate    20  f =       -978.8  |proj g|=     0.0090739
## 
## iterations 21
## function evaluations 30
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00552913
## final function value -978.798
## 
## F = -978.798
## final  value -978.797861 
## converged
## 
print(est.denver.3.1.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 10 converged, 0 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence conv    eigen.min eigen.all.min
## 1  973.9011        TRUE TRUE 0.0013300813            NA
## 2  977.6066        TRUE TRUE 0.0008421307            NA
## 3  984.3069        TRUE TRUE 0.0005586360            NA
## 4  948.7208        TRUE TRUE 0.0009049301            NA
## 5  969.9299        TRUE TRUE 0.0078182691            NA
## 6  991.2142        TRUE TRUE 0.0019499905            NA
## 7  987.7612        TRUE TRUE 0.0013539286            NA
## 8  978.7571        TRUE TRUE 0.0002588020            NA
## 9  983.5494        TRUE TRUE 0.0016914382            NA
## 10 978.7979        TRUE TRUE 0.0010267176            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.3.1, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.3.1.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.1, denver.model.3.1, est.denver.model.3.1, est.denver.3.1.cv,
     file = here::here("Results", "Denver_ST_Model_3.1.rdata"))

8.1.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.3.1.cv <- predictCV(denver.model.3.1, est.denver.3.1.cv, LTA = T)
pred.3.1.cv.log <- predictCV(denver.model.3.1, est.denver.3.1.cv,
                             LTA = T, transform="unbiased")

names(pred.3.1.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.3.1.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.15512985 0.15512985 0.15512985
## average 0.09724282 0.09724282 0.09724282
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.4333046  0.4333046 0.4333046
## average 0.5858357  0.5858357 0.5858357
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9740681
## average 0.7833333
summary(pred.3.1.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.2915129  0.2915129 0.2915139 0.2956075
## average 0.1981780  0.1981780 0.1981790 0.2034073
## 
## R2:
##         EX.mu EX.mu.beta EX EX.pred
## obs         0          0  0       0
## average     0          0  0       0
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9740681
## average 0.7833333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.1.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.1.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod3.1.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.1.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.1.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

8.2 Model 3.2: Smoothing in the error term

8.2.1 Create the model object

For this version of the model, use iid for cov.beta (beta0 and beta1) and exp for cov.nu (error). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data2.1$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR3.2 <- list(covar_fun, covar_fun)

cov.beta3.2 <-  list(covf = c("iid", "iid"), nugget = T)
cov.nu3.2 <- list(covf = "exp", nugget = T, random.effect = FALSE)
locations3.2 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.3.2 <- createSTmodel(denver.data2.1, LUR = LUR3.2,
                                      ST = "bc_st_no2",
                                      cov.beta = cov.beta3.2, cov.nu = cov.nu3.2,
                                      locations = locations3.2)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.3.2
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 1 basis function(s):
## [1] "V1"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, iid 
##  Nugget: Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

8.2.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.3.2, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.nugget.V1.iid"            
## [3] "nu.log.range.exp"              "nu.log.sill.exp"              
## [5] "nu.log.nugget.(Intercept).exp"
# x.init.3.2 <- cbind(c(0, 0, 0, 0, 0),
#                         c(-1, -1, 0, -1, -1),
#                         c(-1, -1, 0, -5, -1),
#                         c(-5, -5, 0, -1, -5),
#                         c(-5, -5, 0, -5, -5),
#                         c(-1, -1, 2, -1, -1),
#                         c(-1, -1, 2, -5, -1),
#                         c(-5, -5, 2, -1, -5),
#                         c(-5, -5, 2, -5, -5),
#                         c(-1, -1, 4, -1, -1),
#                         c(-1, -1, 4, -5, -1),
#                         c(-5, -5, 4, -1, -5),
#                         c(-5, -5, 4, -5, -5))

x.init.3.2 <- cbind(c(0, 0, 0, 0, 0),
                        c(-5, -5, 4, -3, -5),
                        c(-10, -5, 4, -5, -5),
                        c(-5, -5, 6, -3, -5),
                        c(-10, -5, 6, -5, -5),
                        c(-5, -5, 8, -3, -5),
                        c(-10, -5, 8, -5, -5))

rownames(x.init.3.2) <- loglikeSTnames(denver.model.3.2, all=FALSE)
x.init.3.2
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## log.nugget.const.iid             0   -5  -10   -5  -10   -5  -10
## log.nugget.V1.iid                0   -5   -5   -5   -5   -5   -5
## nu.log.range.exp                 0    4    4    6    6    8    8
## nu.log.sill.exp                  0   -3   -5   -3   -5   -3   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5   -5   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.3.2 <- estimate.STmodel(denver.model.3.2, x.init.3.2)
## Optimisation using starting value 1/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       363.45  |proj g|=           15
## At iterate    10  f =      -1077.3  |proj g|=       0.64473
## At iterate    20  f =      -1077.4  |proj g|=    0.00031228
## 
## iterations 20
## function evaluations 43
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.000312276
## final function value -1077.36
## 
## F = -1077.36
## l(0) > u(0).  No feasible solutionfinal  value -1077.359099 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -916.23  |proj g|=           12
## At iterate    10  f =      -1077.1  |proj g|=        1.6592
## ys=-2.531e-03  -gs= 5.296e-02, BFGS update SKIPPED
## ys=-2.598e+01  -gs= 2.054e+00, BFGS update SKIPPED
## At iterate    20  f =        -1343  |proj g|=        20.925
## At iterate    30  f =      -1437.6  |proj g|=        1.8072
## At iterate    40  f =      -1439.7  |proj g|=       0.61903
## 
## iterations 48
## function evaluations 69
## segments explored during Cauchy searches 51
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00474726
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749883 
## converged
## Optimisation using starting value 3/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -994.33  |proj g|=           20
## At iterate    10  f =      -1077.1  |proj g|=        2.1802
## ys=-3.781e-03  -gs= 3.017e-02, BFGS update SKIPPED
## At iterate    20  f =      -1077.4  |proj g|=        3.7251
## ys=-2.110e+02  -gs= 2.016e+00, BFGS update SKIPPED
## At iterate    30  f =      -1439.7  |proj g|=       0.54169
## 
## iterations 32
## function evaluations 45
## segments explored during Cauchy searches 35
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0038238
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749883 
## converged
## Optimisation using starting value 4/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -919.91  |proj g|=           12
## At iterate    10  f =      -1395.8  |proj g|=        8.6784
## At iterate    20  f =      -1437.2  |proj g|=        2.7115
## At iterate    30  f =      -1439.7  |proj g|=       0.11051
## 
## iterations 37
## function evaluations 49
## segments explored during Cauchy searches 40
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00282032
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749883 
## converged
## Optimisation using starting value 5/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -999.68  |proj g|=           20
## At iterate    10  f =      -1355.4  |proj g|=         10.01
## At iterate    20  f =      -1433.9  |proj g|=        6.7177
## 
## iterations 23
## function evaluations 33
## segments explored during Cauchy searches 26
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00233281
## final function value -1434.05
## 
## F = -1434.05
## final  value -1434.049442 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -975.26  |proj g|=           12
## At iterate    10  f =      -1437.6  |proj g|=        2.4648
## At iterate    20  f =      -1439.6  |proj g|=       0.64001
## 
## iterations 28
## function evaluations 43
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.056787
## final function value -1439.75
## 
## F = -1439.75
## l(0) > u(0).  No feasible solutionfinal  value -1439.749897 
## converged
## Optimisation using starting value 7/7
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1065.1  |proj g|=           20
## At iterate    10  f =      -1439.4  |proj g|=        5.8024
## At iterate    20  f =      -1439.7  |proj g|=       0.93811
## 
## iterations 29
## function evaluations 55
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0149428
## final function value -1439.75
## 
## F = -1439.75
## l(0) > u(0).  No feasible solutionfinal  value -1439.749895 
## converged
print(est.denver.model.3.2)
## Optimisation for STmodel with 7 starting points.
##   Results: 5 converged, 2 not converged, 0 failed.
##   Best result for starting point 6, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0103796392   0.0137639004   0.0137633982
## alpha.const.(Intercept)           0.1847485426   0.0437667220   0.0437782154
## alpha.const.impervious_2500       0.0063256775   0.0578203003   0.0578203272
## alpha.const.open_2500            -0.0120293224   0.0185573555   0.0185574549
## alpha.const.low_int_100           0.0232711949   0.0175864985   0.0175863016
## alpha.const.med_int_50            0.0217503239   0.0003318424   0.0003319215
## alpha.const.high_int_50           0.0070865069   0.0077458889   0.0077456521
## alpha.const.high_int_100          0.0137317803   0.0010230185   0.0010234427
## alpha.const.ag_250                0.0031354915   0.0003663073   0.0003662916
## alpha.const.pop_den_50            0.0053470857  -0.0006130943  -0.0006132704
## alpha.const.dist_m_compost        0.0077418468  -0.0021464026  -0.0021461831
## alpha.const.dist_m_military       0.0119559244   0.0016952006   0.0016954305
## alpha.const.len_m_highways_2500  -0.0123430848   0.0013805816   0.0013809416
## alpha.const.aadt_100              0.0201331936   0.0258029945   0.0258029979
## alpha.const.aadt_2500             0.0056895315  -0.0084603347  -0.0084603743
## alpha.V1.(Intercept)             -0.1957500331  -0.1502181239  -0.1502213192
## alpha.V1.impervious_2500         -0.0120210594  -0.0401458717  -0.0401458444
## alpha.V1.open_2500               -0.0266896871  -0.0378671744  -0.0378674501
## alpha.V1.low_int_100             -0.0137074098  -0.0066610620  -0.0066609840
## alpha.V1.med_int_50              -0.0187108852   0.0002560506   0.0002560759
## alpha.V1.high_int_50             -0.0036388756   0.0145133413   0.0145133505
## alpha.V1.high_int_100             0.0053233813  -0.0151917942  -0.0151920345
## alpha.V1.ag_250                   0.0082767070   0.0095440348   0.0095437349
## alpha.V1.pop_den_50              -0.0149134601  -0.0098732948  -0.0098736121
## alpha.V1.dist_m_compost          -0.0217675920  -0.0178635531  -0.0178638031
## alpha.V1.dist_m_military         -0.0061719593  -0.0059049678  -0.0059049835
## alpha.V1.len_m_highways_2500      0.0078111987  -0.0011995401  -0.0011996274
## alpha.V1.aadt_100                 0.0194443216   0.0290022175   0.0290021583
## alpha.V1.aadt_2500                0.0008081706   0.0118681169   0.0118681830
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid               -14.7359895902  -7.1475185578  -7.1478110286
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -4.3673736988  -2.9395133821  -2.9394537594
## nu.log.nugget.(Intercept).exp    -4.6061833483  -5.5006245193  -5.5006195916
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0137636428   0.0133093367   0.0137661316
## alpha.const.(Intercept)           0.0437725897   0.0616716771   0.0437155450
## alpha.const.impervious_2500       0.0578201298   0.0220138724   0.0578193478
## alpha.const.open_2500             0.0185573121  -0.0179474914   0.0185564878
## alpha.const.low_int_100           0.0175862025  -0.0053189745   0.0175864910
## alpha.const.med_int_50            0.0003319682  -0.0065445361   0.0003318777
## alpha.const.high_int_50           0.0077457002   0.0051876264   0.0077466360
## alpha.const.high_int_100          0.0010233470   0.0023521358   0.0010216364
## alpha.const.ag_250                0.0003663172  -0.0005948301   0.0003664580
## alpha.const.pop_den_50           -0.0006131180   0.0043452898  -0.0006120105
## alpha.const.dist_m_compost       -0.0021462538   0.0022069925  -0.0021472140
## alpha.const.dist_m_military       0.0016954056   0.0086899337   0.0016945729
## alpha.const.len_m_highways_2500   0.0013808679   0.0092338373   0.0013794426
## alpha.const.aadt_100              0.0258028874   0.0179855952   0.0258024867
## alpha.const.aadt_2500            -0.0084603079   0.0032039983  -0.0084599458
## alpha.V1.(Intercept)             -0.1502200591  -0.1626829570  -0.1502052729
## alpha.V1.impervious_2500         -0.0401458555  -0.0160422711  -0.0401459836
## alpha.V1.open_2500               -0.0378674625  -0.0126637832  -0.0378666154
## alpha.V1.low_int_100             -0.0066608988   0.0089925382  -0.0066608516
## alpha.V1.med_int_50               0.0002560441   0.0051847029   0.0002558497
## alpha.V1.high_int_50              0.0145133924   0.0158990725   0.0145135104
## alpha.V1.high_int_100            -0.0151921142  -0.0177614545  -0.0151916181
## alpha.V1.ag_250                   0.0095437463   0.0104014033   0.0095447566
## alpha.V1.pop_den_50              -0.0098736459  -0.0121502915  -0.0098727384
## alpha.V1.dist_m_compost          -0.0178639112  -0.0208685681  -0.0178634844
## alpha.V1.dist_m_military         -0.0059050323  -0.0097472759  -0.0059051534
## alpha.V1.len_m_highways_2500     -0.0011996314  -0.0058734584  -0.0011993629
## alpha.V1.aadt_100                 0.0290021563   0.0351747476   0.0290023406
## alpha.V1.aadt_2500                0.0118681541   0.0035045119   0.0118678383
## log.nugget.const.iid            -15.0000000000  -6.5612807692 -15.0000000000
## log.nugget.V1.iid                -7.1478206374 -14.9735967625  -7.1467317754
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -2.9395128019  -2.9425997486  -2.9397375717
## nu.log.nugget.(Intercept).exp    -5.5006032316  -5.4854602622  -5.5003848918
##                                           [,7]
## gamma.bc_st_no2                   0.0137638279
## alpha.const.(Intercept)           0.0437684008
## alpha.const.impervious_2500       0.0578204371
## alpha.const.open_2500             0.0185574383
## alpha.const.low_int_100           0.0175866105
## alpha.const.med_int_50            0.0003317927
## alpha.const.high_int_50           0.0077459031
## alpha.const.high_int_100          0.0010230001
## alpha.const.ag_250                0.0003662922
## alpha.const.pop_den_50           -0.0006131676
## alpha.const.dist_m_compost       -0.0021463969
## alpha.const.dist_m_military       0.0016951711
## alpha.const.len_m_highways_2500   0.0013805604
## alpha.const.aadt_100              0.0258030732
## alpha.const.aadt_2500            -0.0084603746
## alpha.V1.(Intercept)             -0.1502183727
## alpha.V1.impervious_2500         -0.0401458699
## alpha.V1.open_2500               -0.0378671095
## alpha.V1.low_int_100             -0.0066611394
## alpha.V1.med_int_50               0.0002560682
## alpha.V1.high_int_50              0.0145133093
## alpha.V1.high_int_100            -0.0151916877
## alpha.V1.ag_250                   0.0095440881
## alpha.V1.pop_den_50              -0.0098732054
## alpha.V1.dist_m_compost          -0.0178634242
## alpha.V1.dist_m_military         -0.0059049295
## alpha.V1.len_m_highways_2500     -0.0011995192
## alpha.V1.aadt_100                 0.0290022309
## alpha.V1.aadt_2500                0.0118681244
## log.nugget.const.iid            -15.0000000000
## log.nugget.V1.iid                -7.1473717219
## nu.log.range.exp                 15.0000000000
## nu.log.sill.exp                  -2.9394032729
## nu.log.nugget.(Intercept).exp    -5.5005572676
## 
## Function value(s):
## [1] 1077.359 1439.750 1439.750 1439.750 1434.049 1439.750 1439.750

8.2.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.3.2 <- createCV(denver.model.3.2, groups = 10, #min.dist = .1,
                           subset = paste0("d_", c(1:60)))

ID.cv.3.2 <- sapply(split(denver.model.3.2$obs$ID, Ind.cv.3.2), unique)
print(sapply(ID.cv.3.2, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.3.2)
## Ind.cv.3.2
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.3.2 <- apply(sapply(ID.cv.3.2, function(x) denver.model.3.2$locations$ID%in% x), 1,
                       function(x) if(sum(x)==1) which(x) else 0)
names(I.col.3.2) <- denver.model.3.2$locations$ID
print(I.col.3.2)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.3.2$locations$long,
     denver.model.3.2$locations$lat,
     pch=23+floor(I.col.3.2/max(I.col.3.2)+.5), bg=I.col.3.2,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.3.2.cv <- coef(est.denver.model.3.2, pars="cov")[,c("par","init")]
x.init.3.2.cv

Run the model with cross validation

est.denver.3.2.cv <- estimateCV(denver.model.3.2, x.init.3.2.cv, Ind.cv.3.2)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1297.6  |proj g|=       1.4535
## 
## iterations 6
## function evaluations 8
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 5.04053e-05
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.717960 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -887.95  |proj g|=           12
## At iterate    10  f =      -1296.1  |proj g|=        1.0323
## At iterate    20  f =      -1297.7  |proj g|=       0.46454
## 
## iterations 27
## function evaluations 34
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0821066
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.717987 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1308.4  |proj g|=       2.0827
## 
## iterations 6
## function evaluations 8
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000367961
## final function value -1308.53
## 
## F = -1308.53
## final  value -1308.525327 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -891.63  |proj g|=           12
## At iterate    10  f =        -1307  |proj g|=        1.9863
## At iterate    20  f =      -1308.5  |proj g|=       0.41434
## 
## iterations 28
## function evaluations 40
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0234083
## final function value -1308.53
## 
## F = -1308.53
## final  value -1308.525312 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1315.6  |proj g|=       4.2284
## 
## iterations 8
## function evaluations 10
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 2.8308e-07
## final function value -1316.37
## 
## F = -1316.37
## final  value -1316.367235 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -892.96  |proj g|=           12
## At iterate    10  f =      -1314.6  |proj g|=        2.2871
## At iterate    20  f =      -1316.3  |proj g|=       0.43799
## 
## iterations 29
## function evaluations 38
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0878422
## final function value -1316.37
## 
## F = -1316.37
## final  value -1316.367256 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1271.9  |proj g|=       6.0625
## 
## iterations 7
## function evaluations 18
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.028578
## final function value -1272.02
## 
## F = -1272.02
## final  value -1272.018418 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -866.5  |proj g|=           12
## At iterate    10  f =      -1269.5  |proj g|=        3.7506
## At iterate    20  f =      -1271.9  |proj g|=       0.49847
## 
## iterations 29
## function evaluations 39
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0023411
## final function value -1272.02
## 
## F = -1272.02
## final  value -1272.018415 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1294.9  |proj g|=       3.6481
## 
## iterations 8
## function evaluations 18
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00547364
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.961756 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -881.83  |proj g|=           12
## At iterate    10  f =      -1292.4  |proj g|=        1.8405
## At iterate    20  f =      -1294.9  |proj g|=        1.3085
## 
## iterations 28
## function evaluations 36
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0369132
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.961765 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1322.6  |proj g|=       6.8207
## 
## iterations 7
## function evaluations 25
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0129926
## final function value -1322.71
## 
## F = -1322.71
## l(0) > u(0).  No feasible solutionfinal  value -1322.714136 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -905.27  |proj g|=           12
## At iterate    10  f =      -1320.2  |proj g|=         2.318
## At iterate    20  f =      -1322.7  |proj g|=       0.85682
## 
## iterations 26
## function evaluations 31
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00709257
## final function value -1322.71
## 
## F = -1322.71
## final  value -1322.714126 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1318.6  |proj g|=       2.9525
## 
## iterations 9
## function evaluations 27
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000117693
## final function value -1318.87
## 
## F = -1318.87
## l(0) > u(0).  No feasible solutionfinal  value -1318.868053 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -896.84  |proj g|=           12
## At iterate    10  f =      -1315.1  |proj g|=         4.111
## At iterate    20  f =      -1318.8  |proj g|=       0.53139
## 
## iterations 28
## function evaluations 40
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00155084
## final function value -1318.87
## 
## F = -1318.87
## final  value -1318.868053 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1305.7  |proj g|=       1.9583
## 
## iterations 9
## function evaluations 14
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0550613
## final function value -1305.76
## 
## F = -1305.76
## final  value -1305.755734 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -886.85  |proj g|=           12
## At iterate    10  f =      -1303.5  |proj g|=        2.4072
## At iterate    20  f =      -1305.7  |proj g|=       0.71326
## 
## iterations 29
## function evaluations 38
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0965218
## final function value -1305.76
## 
## F = -1305.76
## final  value -1305.755758 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1314.3  |proj g|=       5.6011
## 
## iterations 8
## function evaluations 27
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00346559
## final function value -1314.35
## 
## F = -1314.35
## l(0) > u(0).  No feasible solutionfinal  value -1314.349289 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -888.89  |proj g|=           12
## At iterate    10  f =      -1312.5  |proj g|=        1.0418
## At iterate    20  f =      -1314.3  |proj g|=        1.7549
## 
## iterations 28
## function evaluations 34
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00378655
## final function value -1314.35
## 
## F = -1314.35
## final  value -1314.349288 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=        -1307  |proj g|=       4.5212
## 
## iterations 7
## function evaluations 10
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 1.72599e-06
## final function value -1307.05
## 
## F = -1307.05
## final  value -1307.048074 
## converged
## 
## Optimisation using starting value 2/2
## N = 5, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -883.54  |proj g|=           12
## At iterate    10  f =      -1304.7  |proj g|=         2.917
## At iterate    20  f =        -1307  |proj g|=       0.43934
## At iterate    30  f =        -1307  |proj g|=     0.0015643
## 
## iterations 31
## function evaluations 43
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00156442
## final function value -1307.05
## 
## F = -1307.05
## final  value -1307.048074 
## converged
## 
print(est.denver.3.2.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 10 converged, 0 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence conv    eigen.min eigen.all.min
## 1  1297.718        TRUE TRUE 0.0012876515            NA
## 2  1308.525        TRUE TRUE 0.0008997211            NA
## 3  1316.367        TRUE TRUE 0.0015291503            NA
## 4  1272.018        TRUE TRUE 0.0015197317            NA
## 5  1294.962        TRUE TRUE 0.0030796534            NA
## 6  1322.714        TRUE TRUE 0.0031276394            NA
## 7  1318.868        TRUE TRUE 0.0014500470            NA
## 8  1305.756        TRUE TRUE 0.0016715650            NA
## 9  1314.349        TRUE TRUE 0.0018736205            NA
## 10 1307.048        TRUE TRUE 0.0019298700            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.3.2, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
             col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.3.2.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.1, denver.model.3.2, est.denver.model.3.2, est.denver.3.2.cv,
     file = here::here("Results", "Denver_ST_Model_3.2.rdata"))

8.2.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.3.2.cv <- predictCV(denver.model.3.2, est.denver.3.2.cv, LTA = T)
pred.3.2.cv.log <- predictCV(denver.model.3.2, est.denver.3.2.cv,
                             LTA = T, transform="unbiased")

names(pred.3.2.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.3.2.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.12790109 0.12790109 0.08531126
## average 0.07048811 0.07048811 0.05786869
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6147812  0.6147812 0.8286155
## average 0.7823848  0.7823848 0.8533288
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9238250
## average 0.8333333
summary(pred.3.2.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.15172057 0.15172057 0.09902362 0.09913922
## average 0.08378928 0.08378928 0.06528140 0.06564921
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6435631  0.6435631 0.8481652 0.8478105
## average 0.8110992  0.8110992 0.8853337 0.8840380
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9238250
## average 0.8333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.2.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.2.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod3.2.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.2.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.2.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

8.3 Model 3.3: Smoothing in beta0 and the error term

8.3.1 Create the model object

For this version of the model, use iid for cov.beta (beta1) and exp for cov.beta (beta0) cov.nu (error).

Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data2.1$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR3.3 <- list(covar_fun, covar_fun)

cov.beta3.3 <-  list(covf = c("exp", "iid"), nugget = T)
cov.nu3.3 <- list(covf = "exp", nugget = T, random.effect = FALSE)
locations3.3 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.3.3 <- createSTmodel(denver.data2.1, LUR = LUR3.3,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta3.3, cov.nu = cov.nu3.3,
                                  locations = locations3.3)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.3.3
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 1 basis function(s):
## [1] "V1"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): exp, iid 
##  Nugget: Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

8.3.2 Estimate model parameters

Josh gave some guidance on how to set up the initial values (NOTE: the iid model doesn’t have range or sill values, but the exp model does):

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.3.3, all=FALSE)
names
## [1] "log.range.const.exp"           "log.sill.const.exp"           
## [3] "log.nugget.const.exp"          "log.nugget.V1.iid"            
## [5] "nu.log.range.exp"              "nu.log.sill.exp"              
## [7] "nu.log.nugget.(Intercept).exp"
# x.init.3.3 <- cbind(c(0, 0, 0, 0, 0, 0, 0),
#                     c(0, -1, -1, -1, 0, -1, -1),
#                     c(0, -1, -5, -5, 0, -1, -1),
#                     c(0, -5, -1, -1, 0, -5, -5),
#                     c(0, -5, -5, -5, 0, -5, -5),
#                     c(2, -1, -1, -1, 2, -1, -1),
#                     c(2, -1, -5, -5, 2, -1, -1),
#                     c(2, -5, -1, -1, 2, -5, -5),
#                     c(2, -5, -5, -5, 2, -5, -5),
#                     c(4, -1, -1, -1, 4, -1, -1),
#                     c(4, -1, -5, -5, 4, -1, -1),
#                     c(4, -5, -1, -1, 4, -5, -5),
#                     c(4, -5, -5, -5, 4, -5, -5),
#                     c(6, -1, -1, -1, 6, -1, -1),
#                     c(6, -1, -5, -5, 6, -1, -1),
#                     c(6, -5, -1, -1, 6, -5, -5),
#                     c(6, -5, -5, -5, 6, -5, -5)
#                     )
# x.init.3.3[nrow(x.init.3.3),] <- 0

x.init.3.3 <- cbind(c(0, 0, 0, 0, 0, 0, 0),
                    c(4, -1, -1, -1, 6, -1, -1),
                    c(4, -1, -5, -5, 6, -1, -1),
                    c(4, -10, -10, -1, 6, -3, -5),
                    c(4, -10, -5, -5, 6, -3, -5),
                    c(6, -1, -1, -1, 10, -1, -1),
                    c(6, -1, -5, -5, 10, -1, -1),
                    c(6, -10, -10, -1, 10, -3, -5),
                    c(6, -10, -5, -5, 10, -3, -5)
                    )

rownames(x.init.3.3) <- loglikeSTnames(denver.model.3.3, all=FALSE)
x.init.3.3
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## log.range.const.exp              0    4    4    4    4    6    6    6    6
## log.sill.const.exp               0   -1   -1  -10  -10   -1   -1  -10  -10
## log.nugget.const.exp             0   -1   -5  -10   -5   -1   -5  -10   -5
## log.nugget.V1.iid                0   -1   -5   -1   -5   -1   -5   -1   -5
## nu.log.range.exp                 0    6    6    6    6   10   10   10   10
## nu.log.sill.exp                  0   -1   -1   -3   -3   -1   -1   -3   -3
## nu.log.nugget.(Intercept).exp    0   -1   -1   -5   -5   -1   -1   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.3.3 <- estimate.STmodel(denver.model.3.3, x.init.3.3)
## Optimisation using starting value 1/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       375.69  |proj g|=           15
## At iterate    10  f =      -1076.2  |proj g|=        8.1739
## At iterate    20  f =      -1077.3  |proj g|=       0.75997
## 
## iterations 28
## function evaluations 46
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0145169
## final function value -1077.36
## 
## F = -1077.36
## l(0) > u(0).  No feasible solutionfinal  value -1077.356097 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -4.1003  |proj g|=           14
## At iterate    10  f =      -1354.7  |proj g|=        6.4914
## At iterate    20  f =      -1395.5  |proj g|=        0.2914
## At iterate    30  f =        -1434  |proj g|=       0.41575
## At iterate    40  f =        -1434  |proj g|=       0.43617
## At iterate    50  f =      -1434.1  |proj g|=       0.41235
## 
## iterations 56
## function evaluations 77
## segments explored during Cauchy searches 59
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0305993
## final function value -1434.08
## 
## F = -1434.08
## final  value -1434.077622 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -52.797  |proj g|=           14
## At iterate    10  f =      -1412.6  |proj g|=        14.397
## At iterate    20  f =      -1434.1  |proj g|=       0.46853
## At iterate    30  f =      -1435.3  |proj g|=        8.6255
## At iterate    40  f =      -1439.7  |proj g|=        1.2889
## 
## iterations 48
## function evaluations 80
## segments explored during Cauchy searches 51
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0361028
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.747900 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -832.59  |proj g|=           14
## At iterate    10  f =      -1356.1  |proj g|=        18.569
## At iterate    20  f =      -1429.5  |proj g|=         20.55
## At iterate    30  f =        -1434  |proj g|=       0.14699
## At iterate    40  f =        -1434  |proj g|=       0.19806
## At iterate    50  f =        -1434  |proj g|=      0.002615
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 51
## function evaluations 81
## segments explored during Cauchy searches 55
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00352171
## final function value -1434.05
## 
## F = -1434.05
## final  value -1434.049672 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 5/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -919.85  |proj g|=           12
## At iterate    10  f =      -1400.2  |proj g|=        10.911
## At iterate    20  f =      -1433.4  |proj g|=       0.24037
## At iterate    30  f =      -1437.6  |proj g|=        7.1258
## At iterate    40  f =      -1439.5  |proj g|=       0.22987
## At iterate    50  f =      -1439.7  |proj g|=       0.21595
## 
## iterations 55
## function evaluations 71
## segments explored during Cauchy searches 58
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0147453
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.747893 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -86.763  |proj g|=           14
## At iterate    10  f =      -1435.1  |proj g|=        2.3486
## At iterate    20  f =      -1437.5  |proj g|=        2.5613
## At iterate    30  f =      -1439.7  |proj g|=       0.91791
## 
## iterations 34
## function evaluations 53
## segments explored during Cauchy searches 38
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0644593
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.747559 
## converged
## Optimisation using starting value 7/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -139.72  |proj g|=           14
## At iterate    10  f =      -1436.2  |proj g|=        6.3487
## At iterate    20  f =      -1439.6  |proj g|=       0.47157
## At iterate    30  f =      -1439.7  |proj g|=      0.095224
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1439.748118 
## stopped after 38 iterations
## Optimisation using starting value 8/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1074.7  |proj g|=           14
## At iterate    10  f =      -1439.3  |proj g|=        0.4161
## At iterate    20  f =      -1439.7  |proj g|=       0.73698
## 
## iterations 25
## function evaluations 28
## segments explored during Cauchy searches 29
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.005048
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.746682 
## converged
## Optimisation using starting value 9/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1162.9  |proj g|=           12
## At iterate    10  f =      -1437.6  |proj g|=        1.5341
## At iterate    20  f =      -1439.6  |proj g|=       0.55674
## At iterate    30  f =      -1439.7  |proj g|=        1.9362
## At iterate    40  f =      -1439.7  |proj g|=     0.0023248
## 
## iterations 40
## function evaluations 54
## segments explored during Cauchy searches 45
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00232476
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.748112 
## converged
print(est.denver.model.3.3)
## Optimisation for STmodel with 9 starting points.
##   Results: 3 converged, 6 not converged, 0 failed.
##   Best result for starting point 7, optimisation has NOT converged
##   Best converged result for starting point 9 
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0103809381   0.0133093834   0.0137648149
## alpha.const.(Intercept)           0.1847188602   0.0615422496   0.0437409474
## alpha.const.impervious_2500       0.0063370411   0.0222062144   0.0578093537
## alpha.const.open_2500            -0.0120240574  -0.0177371531   0.0185472401
## alpha.const.low_int_100           0.0232782877  -0.0052139466   0.0175793752
## alpha.const.med_int_50            0.0217424444  -0.0064867666   0.0003309904
## alpha.const.high_int_50           0.0070898507   0.0051900079   0.0077442110
## alpha.const.high_int_100          0.0137251478   0.0023662245   0.0010254951
## alpha.const.ag_250                0.0031338410  -0.0005823268   0.0003665606
## alpha.const.pop_den_50            0.0053447687   0.0043410594  -0.0006103765
## alpha.const.dist_m_compost        0.0077395635   0.0021824877  -0.0021449454
## alpha.const.dist_m_military       0.0119561886   0.0086559530   0.0016977917
## alpha.const.len_m_highways_2500  -0.0123469901   0.0091801868   0.0013822046
## alpha.const.aadt_100              0.0201362218   0.0180204336   0.0257989616
## alpha.const.aadt_2500             0.0056881398   0.0031602380  -0.0084562770
## alpha.V1.(Intercept)             -0.1957360062  -0.1625400920  -0.1502103129
## alpha.V1.impervious_2500         -0.0120272693  -0.0161778665  -0.0401394994
## alpha.V1.open_2500               -0.0266897105  -0.0128167237  -0.0378604734
## alpha.V1.low_int_100             -0.0137132194   0.0089197242  -0.0066560100
## alpha.V1.med_int_50              -0.0187049643   0.0051404086   0.0002561717
## alpha.V1.high_int_50             -0.0036455246   0.0158943545   0.0145141079
## alpha.V1.high_int_100             0.0053363710  -0.0177461933  -0.0151923595
## alpha.V1.ag_250                   0.0082865421   0.0103888025   0.0095444194
## alpha.V1.pop_den_50              -0.0149099728  -0.0121615375  -0.0098742849
## alpha.V1.dist_m_compost          -0.0217572369  -0.0208504003  -0.0178643436
## alpha.V1.dist_m_military         -0.0061617410  -0.0097257868  -0.0059064937
## alpha.V1.len_m_highways_2500      0.0078147861  -0.0058399222  -0.0012006244
## alpha.V1.aadt_100                 0.0194509021   0.0351467322   0.0290042068
## alpha.V1.aadt_2500                0.0008134092   0.0035368491   0.0118653044
## log.range.const.exp               0.0000000000   4.2962126507   4.0001787109
## log.sill.const.exp              -14.8716256465 -15.0000000000 -15.0000000000
## log.nugget.const.exp            -15.0000000000  -6.5692809617 -15.0000000000
## log.nugget.V1.iid               -13.0118625635 -12.3988245337  -7.1472071258
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -4.3667142126  -2.9423147509  -2.9395025400
## nu.log.nugget.(Intercept).exp    -4.6071941318  -5.4855843591  -5.5004762350
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0133094761   0.0137645953   0.0137588179
## alpha.const.(Intercept)           0.0616663735   0.0437459638   0.0438764063
## alpha.const.impervious_2500       0.0220157177   0.0578093928   0.0578099624
## alpha.const.open_2500            -0.0179454091   0.0185473049   0.0185479320
## alpha.const.low_int_100          -0.0053178806   0.0175793014   0.0175771622
## alpha.const.med_int_50           -0.0065440376   0.0003310141   0.0003300971
## alpha.const.high_int_50           0.0051874791   0.0077441055   0.0077413642
## alpha.const.high_int_100          0.0023526103   0.0010256781   0.0010304166
## alpha.const.ag_250               -0.0005946787   0.0003665516   0.0003661155
## alpha.const.pop_den_50            0.0043453372  -0.0006104532  -0.0006120374
## alpha.const.dist_m_compost        0.0022067276  -0.0021448491  -0.0021419293
## alpha.const.dist_m_military       0.0086896388   0.0016978844   0.0017001246
## alpha.const.len_m_highways_2500   0.0092332436   0.0013823659   0.0013868486
## alpha.const.aadt_100              0.0179855597   0.0257989687   0.0257989983
## alpha.const.aadt_2500             0.0032035689  -0.0084562973  -0.0084562073
## alpha.V1.(Intercept)             -0.1626804792  -0.1502116807  -0.1502436455
## alpha.V1.impervious_2500         -0.0160437979  -0.0401394939  -0.0401381923
## alpha.V1.open_2500               -0.0126654405  -0.0378605881  -0.0378608388
## alpha.V1.low_int_100              0.0089918194  -0.0066559835  -0.0066551743
## alpha.V1.med_int_50               0.0051842318   0.0002561867   0.0002571633
## alpha.V1.high_int_50              0.0158990037   0.0145141124   0.0145141128
## alpha.V1.high_int_100            -0.0177612226  -0.0151924536  -0.0151935493
## alpha.V1.ag_250                   0.0104012706   0.0095443009   0.0095425891
## alpha.V1.pop_den_50              -0.0121503944  -0.0098744102  -0.0098762033
## alpha.V1.dist_m_compost          -0.0208684253  -0.0178644354  -0.0178648291
## alpha.V1.dist_m_military         -0.0097471182  -0.0059064958  -0.0059064103
## alpha.V1.len_m_highways_2500     -0.0058731085  -0.0012006631  -0.0012015929
## alpha.V1.aadt_100                 0.0351743553   0.0290041864   0.0290047223
## alpha.V1.aadt_2500                0.0035048462   0.0118653324   0.0118652654
## log.range.const.exp               4.2404453333   4.2290605364   6.0566206255
## log.sill.const.exp              -15.0000000000 -15.0000000000 -14.7536874085
## log.nugget.const.exp             -6.5615729526 -15.0000000000 -15.0000000000
## log.nugget.V1.iid               -14.8605001269  -7.1474000912  -7.1489850627
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -2.9426213945  -2.9395513250  -2.9385445481
## nu.log.nugget.(Intercept).exp    -5.4854461734  -5.5005529832  -5.5007812013
##                                           [,7]           [,8]           [,9]
## gamma.bc_st_no2                   0.0137638657   0.0137639278   0.0137635960
## alpha.const.(Intercept)           0.0437620784   0.0437562909   0.0437682692
## alpha.const.impervious_2500       0.0578102149   0.0578021141   0.0578103120
## alpha.const.open_2500             0.0185483042   0.0185410028   0.0185483977
## alpha.const.low_int_100           0.0175787751   0.0175726079   0.0175787485
## alpha.const.med_int_50            0.0003306102   0.0003295539   0.0003305953
## alpha.const.high_int_50           0.0077435281   0.0077416772   0.0077434291
## alpha.const.high_int_100          0.0010266151   0.0010294272   0.0010267998
## alpha.const.ag_250                0.0003664377   0.0003665339   0.0003664163
## alpha.const.pop_den_50           -0.0006101512  -0.0006077357  -0.0006102611
## alpha.const.dist_m_compost       -0.0021442037  -0.0021424535  -0.0021440875
## alpha.const.dist_m_military       0.0016980807   0.0017003354   0.0016981601
## alpha.const.len_m_highways_2500   0.0013837550   0.0013862543   0.0013839180
## alpha.const.aadt_100              0.0257987360   0.0257953161   0.0257987819
## alpha.const.aadt_2500            -0.0084563269  -0.0084530950  -0.0084563677
## alpha.V1.(Intercept)             -0.1502159542  -0.1502135786  -0.1502175397
## alpha.V1.impervious_2500         -0.0401401367  -0.0401355377  -0.0401401354
## alpha.V1.open_2500               -0.0378615690  -0.0378569811  -0.0378616576
## alpha.V1.low_int_100             -0.0066558673  -0.0066517223  -0.0066558837
## alpha.V1.med_int_50               0.0002565977   0.0002570613   0.0002566338
## alpha.V1.high_int_50              0.0145143529   0.0145151636   0.0145143406
## alpha.V1.high_int_100            -0.0151933211  -0.0151944988  -0.0151933789
## alpha.V1.ag_250                   0.0095439282   0.0095439257   0.0095438294
## alpha.V1.pop_den_50              -0.0098749589  -0.0098762093  -0.0098750465
## alpha.V1.dist_m_compost          -0.0178648894  -0.0178658839  -0.0178649250
## alpha.V1.dist_m_military         -0.0059065281  -0.0059077717  -0.0059065112
## alpha.V1.len_m_highways_2500     -0.0012009020  -0.0012019653  -0.0012009220
## alpha.V1.aadt_100                 0.0290043689   0.0290061311   0.0290043574
## alpha.V1.aadt_2500                0.0118653982   0.0118631916   0.0118654311
## log.range.const.exp               6.2485535457   6.2826667124   6.2855985153
## log.sill.const.exp              -15.0000000000 -14.4086109017 -15.0000000000
## log.nugget.const.exp            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid                -7.1478299908  -7.1480854380  -7.1479584718
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -2.9394754125  -2.9395382239  -2.9394707172
## nu.log.nugget.(Intercept).exp    -5.5005515655  -5.5005852278  -5.5005976731
## 
## Function value(s):
## [1] 1077.356 1434.078 1439.748 1434.050 1439.748 1439.748 1439.748 1439.747
## [9] 1439.748

8.3.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.3.3 <- createCV(denver.model.3.3, groups = 10, #min.dist = .1,
                           subset = paste0("d_", c(1:60)))

ID.cv.3.3 <- sapply(split(denver.model.3.3$obs$ID, Ind.cv.3.3), unique)
print(sapply(ID.cv.3.3, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.3.3)
## Ind.cv.3.3
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.3.3 <- apply(sapply(ID.cv.3.3, function(x) denver.model.3.3$locations$ID%in% x), 1,
                       function(x) if(sum(x)==1) which(x) else 0)
names(I.col.3.3) <- denver.model.3.3$locations$ID
print(I.col.3.3)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.3.3$locations$long,
     denver.model.3.3$locations$lat,
     pch=23+floor(I.col.3.3/max(I.col.3.3)+.5), bg=I.col.3.3,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.3.3.cv <- coef(est.denver.model.3.3, pars="cov")[,c("par","init")]
x.init.3.3.cv

Run the model with cross validation

est.denver.3.3.cv <- estimateCV(denver.model.3.3, x.init.3.3.cv, Ind.cv.3.3)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1297.6  |proj g|=       1.4692
## 
## iterations 6
## function evaluations 8
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 2.75145e-06
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.716707 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1050.7  |proj g|=           12
## At iterate    10  f =      -1296.1  |proj g|=         1.352
## At iterate    20  f =      -1297.7  |proj g|=       0.50077
## At iterate    30  f =      -1297.7  |proj g|=       0.96191
## 
## iterations 38
## function evaluations 45
## segments explored during Cauchy searches 44
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0144458
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.716701 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1308.4  |proj g|=       2.0681
## 
## iterations 6
## function evaluations 9
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00733992
## final function value -1308.52
## 
## F = -1308.52
## final  value -1308.524196 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1058  |proj g|=           12
## At iterate    10  f =      -1307.1  |proj g|=       0.94358
## At iterate    20  f =      -1308.4  |proj g|=       0.55501
## At iterate    30  f =      -1308.4  |proj g|=       0.13143
## At iterate    40  f =      -1308.5  |proj g|=      0.072683
## 
## iterations 43
## function evaluations 49
## segments explored during Cauchy searches 48
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.000154468
## final function value -1308.52
## 
## F = -1308.52
## final  value -1308.524208 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1315.6  |proj g|=        4.215
## 
## iterations 8
## function evaluations 10
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 6.07442e-05
## final function value -1316.37
## 
## F = -1316.37
## final  value -1316.365635 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1059.4  |proj g|=           12
## At iterate    10  f =      -1314.8  |proj g|=        1.6182
## At iterate    20  f =      -1316.2  |proj g|=       0.73781
## At iterate    30  f =      -1316.3  |proj g|=       0.55175
## At iterate    40  f =      -1316.4  |proj g|=      0.034916
## 
## iterations 40
## function evaluations 51
## segments explored during Cauchy searches 45
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0349162
## final function value -1316.37
## 
## F = -1316.37
## final  value -1316.365632 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1271.9  |proj g|=       6.1103
## 
## iterations 7
## function evaluations 26
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0299705
## final function value -1272.02
## 
## F = -1272.02
## l(0) > u(0).  No feasible solutionfinal  value -1272.017050 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1028.8  |proj g|=           12
## At iterate    10  f =      -1269.8  |proj g|=        3.5778
## At iterate    20  f =      -1271.9  |proj g|=       0.76785
## At iterate    30  f =        -1272  |proj g|=       0.62861
## 
## iterations 39
## function evaluations 63
## segments explored during Cauchy searches 44
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0119128
## final function value -1272.02
## 
## F = -1272.02
## l(0) > u(0).  No feasible solutionfinal  value -1272.017052 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1294.9  |proj g|=          3.7
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 8
## function evaluations 38
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0115302
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.958628 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1046  |proj g|=           12
## At iterate    10  f =      -1292.3  |proj g|=         2.024
## At iterate    20  f =      -1294.8  |proj g|=       0.27531
## At iterate    30  f =        -1295  |proj g|=      0.039901
## 
## iterations 33
## function evaluations 39
## segments explored during Cauchy searches 38
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00309077
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.958645 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1322.6  |proj g|=       6.8735
## 
## iterations 7
## function evaluations 16
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0204631
## final function value -1322.71
## 
## F = -1322.71
## final  value -1322.711231 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1075  |proj g|=           12
## At iterate    10  f =      -1320.4  |proj g|=        1.6936
## At iterate    20  f =      -1322.6  |proj g|=       0.15609
## At iterate    30  f =      -1322.7  |proj g|=        1.0199
## 
## iterations 35
## function evaluations 45
## segments explored during Cauchy searches 41
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0023693
## final function value -1322.71
## 
## F = -1322.71
## final  value -1322.711216 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1318.6  |proj g|=       3.0017
## 
## iterations 9
## function evaluations 21
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00108013
## final function value -1318.87
## 
## F = -1318.87
## final  value -1318.866843 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1067.7  |proj g|=           12
## At iterate    10  f =      -1316.4  |proj g|=        3.5915
## At iterate    20  f =      -1318.7  |proj g|=        1.4357
## At iterate    30  f =      -1318.8  |proj g|=       0.26959
## At iterate    40  f =      -1318.9  |proj g|=      0.042938
## 
## iterations 41
## function evaluations 48
## segments explored during Cauchy searches 46
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.034695
## final function value -1318.87
## 
## F = -1318.87
## final  value -1318.866877 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1305.7  |proj g|=       2.0078
## 
## iterations 8
## function evaluations 12
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0726116
## final function value -1305.75
## 
## F = -1305.75
## final  value -1305.754079 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1053.2  |proj g|=           12
## At iterate    10  f =      -1303.9  |proj g|=        3.4363
## At iterate    20  f =      -1305.6  |proj g|=        1.4895
## At iterate    30  f =      -1305.7  |proj g|=       0.35787
## 
## iterations 38
## function evaluations 52
## segments explored during Cauchy searches 44
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0214886
## final function value -1305.75
## 
## F = -1305.75
## final  value -1305.754081 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1314.3  |proj g|=       5.6518
## 
## iterations 8
## function evaluations 14
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00329925
## final function value -1314.35
## 
## F = -1314.35
## final  value -1314.347594 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1057.4  |proj g|=           12
## At iterate    10  f =      -1312.6  |proj g|=        5.0408
## At iterate    20  f =      -1314.2  |proj g|=       0.32433
## At iterate    30  f =      -1314.3  |proj g|=      0.079637
## 
## iterations 36
## function evaluations 45
## segments explored during Cauchy searches 41
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0869106
## final function value -1314.35
## 
## F = -1314.35
## final  value -1314.347627 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=        -1307  |proj g|=       4.4731
## 
## iterations 7
## function evaluations 10
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 5.41686e-05
## final function value -1307.05
## 
## F = -1307.05
## final  value -1307.046399 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1049.8  |proj g|=           12
## At iterate    10  f =      -1304.9  |proj g|=        1.7523
## At iterate    20  f =      -1306.9  |proj g|=       0.65638
## At iterate    30  f =        -1307  |proj g|=        1.4553
## At iterate    40  f =        -1307  |proj g|=     0.0042022
## 
## iterations 42
## function evaluations 52
## segments explored during Cauchy searches 47
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00154053
## final function value -1307.05
## 
## F = -1307.05
## final  value -1307.046399 
## converged
## 
print(est.denver.3.3.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 10 converged, 0 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence conv     eigen.min eigen.all.min
## 1  1297.717        TRUE TRUE 0.00023497870            NA
## 2  1308.524        TRUE TRUE 0.00008782019            NA
## 3  1316.366        TRUE TRUE 0.00024016594            NA
## 4  1272.017        TRUE TRUE 0.00022412895            NA
## 5  1294.959        TRUE TRUE 0.00020157021            NA
## 6  1322.711        TRUE TRUE 0.00021108225            NA
## 7  1318.867        TRUE TRUE 0.00004430623            NA
## 8  1305.754        TRUE TRUE 0.00034240674            NA
## 9  1314.348        TRUE TRUE 0.00026524426            NA
## 10 1307.046        TRUE TRUE 0.00006248069            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.3.3, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
             col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.3.3.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.1, denver.model.3.3, est.denver.model.3.3, est.denver.3.3.cv,
     file = here::here("Results", "Denver_ST_Model_3.3.rdata"))

8.3.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.3.3.cv <- predictCV(denver.model.3.3, est.denver.3.3.cv, LTA = T)
pred.3.3.cv.log <- predictCV(denver.model.3.3, est.denver.3.3.cv,
                             LTA = T, transform="unbiased")

names(pred.3.3.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.3.3.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.12790139 0.12790128 0.08531156
## average 0.07048763 0.07048739 0.05786844
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6147794  0.6147801 0.8286142
## average 0.7823878  0.7823893 0.8533301
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9238250
## average 0.8333333
summary(pred.3.3.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.15172118 0.15172110 0.09902449 0.09914009
## average 0.08378889 0.08378867 0.06528135 0.06564917
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6435602  0.6435606 0.8481625 0.8478078
## average 0.8111010  0.8111020 0.8853339 0.8840381
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9238250
## average 0.8333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.3.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.3.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod3.3.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.3.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.3.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

8.4 Model 3.4: Smoothing for beta1 and error term

For this version of the model, use iid for cov.beta (beta0) and exp for cov.beta (beta1) cov.nu (error).

8.4.1 Create the model object

names(denver.data2.1$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR3.4<- list(covar_fun, covar_fun)

cov.beta3.4 <-  list(covf=c("iid", "exp"), nugget = c(TRUE, TRUE))
cov.nu3.4 <- list(covf="exp", nugget = T, random.effect = FALSE)
locations3.4 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.3.4 <- createSTmodel(denver.data2.1, LUR = LUR3.4,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta3.4, cov.nu = cov.nu3.4,
                                  locations = locations3.4)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.3.4
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 1 basis function(s):
## [1] "V1"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, exp 
##  Nugget: Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

8.4.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.3.4, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.range.V1.exp"             
## [3] "log.sill.V1.exp"               "log.nugget.V1.exp"            
## [5] "nu.log.range.exp"              "nu.log.sill.exp"              
## [7] "nu.log.nugget.(Intercept).exp"
# x.init.3.4 <- cbind(c(0, 0, 0, 0, 0),
#                     c(-1, 0, -1, -1, 0, -1, -1),
#                     c(-1, 0, -1, -5, 0, -5, -1),
#                     c(-5, 0, -5, -1, 0, -1, -5),
#                     c(-5, 0, -5, -5, 0, -5, -5),
#                     c(-1, 2, -1, -1, 2, -1, -1),
#                     c(-1, 2, -1, -5, 2, -5, -1),
#                     c(-5, 2, -5, -1, 2, -1, -5),
#                     c(-5, 2, -5, -5, 2, -5, -5),
#                     c(-1, 4, -1, -1, 4, -1, -1),
#                     c(-1, 4, -1, -5, 4, -5, -1),
#                     c(-5, 4, -5, -5, 4, -1, -5),
#                     c(-5, 4, -5, -5, 4, -5, -5))
# x.init.3.4[nrow(x.init.3.4),] <- 0

x.init.3.4 <- cbind(c(0, 0, 0, 0, 0, 0, 0),
                    c(-5, 4, -5, -1, 8, -1, -5),
                    c(-5, 4, -5, -5, 8, -5, -5),
                    c(-10, 4, -1, -1, 8, -1, -5),
                    c(-10, 4, -1, -5, 8, -5, -5),
                    c(-5, 4, -10, -1, 8, -1, -5),
                    c(-5, 4, -10, -5, 8, -5, -5),
                    c(-10, 4, -10, -1, 8, -1, -5),
                    c(-10, 4, -10, -5, 8, -5, -5))

rownames(x.init.3.4) <- loglikeSTnames(denver.model.3.4, all=FALSE)
x.init.3.4
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## log.nugget.const.iid             0   -5   -5  -10  -10   -5   -5  -10  -10
## log.range.V1.exp                 0    4    4    4    4    4    4    4    4
## log.sill.V1.exp                  0   -5   -5   -1   -1  -10  -10  -10  -10
## log.nugget.V1.exp                0   -1   -5   -1   -5   -1   -5   -1   -5
## nu.log.range.exp                 0    8    8    8    8    8    8    8    8
## nu.log.sill.exp                  0   -1   -5   -1   -5   -1   -5   -1   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5   -5   -5   -5   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.3.4 <- estimate.STmodel(denver.model.3.4, x.init.3.4)
## Optimisation using starting value 1/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        378.8  |proj g|=           15
## At iterate    10  f =      -1077.2  |proj g|=       0.92106
## At iterate    20  f =      -1077.4  |proj g|=      0.059965
## 
## iterations 25
## function evaluations 36
## segments explored during Cauchy searches 27
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00156691
## final function value -1077.36
## 
## F = -1077.36
## final  value -1077.358154 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -338.53  |proj g|=           14
## At iterate    10  f =      -1434.8  |proj g|=        10.627
## At iterate    20  f =        -1439  |proj g|=        3.4999
## At iterate    30  f =      -1439.7  |proj g|=      0.018212
## At iterate    40  f =      -1439.7  |proj g|=       0.44448
## 
## iterations 47
## function evaluations 61
## segments explored during Cauchy searches 50
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0132629
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749556 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1030.1  |proj g|=           20
## At iterate    10  f =      -1437.7  |proj g|=        1.4251
## At iterate    20  f =      -1439.6  |proj g|=       0.64917
## At iterate    30  f =      -1439.7  |proj g|=      0.061383
## At iterate    40  f =      -1439.7  |proj g|=      0.058061
## 
## iterations 44
## function evaluations 53
## segments explored during Cauchy searches 50
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0103423
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749551 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -322.75  |proj g|=           14
## At iterate    10  f =      -1438.8  |proj g|=        1.7873
## At iterate    20  f =      -1439.6  |proj g|=       0.61316
## 
## iterations 28
## function evaluations 32
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0310298
## final function value -1439.73
## 
## F = -1439.73
## final  value -1439.730676 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 5/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -960.21  |proj g|=           20
## At iterate    10  f =      -1437.1  |proj g|=        6.1373
## At iterate    20  f =      -1439.6  |proj g|=        2.3533
## At iterate    30  f =      -1439.7  |proj g|=       0.01103
## 
## iterations 32
## function evaluations 45
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0060484
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749072 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -339.02  |proj g|=           14
## At iterate    10  f =      -1435.5  |proj g|=        1.7564
## At iterate    20  f =      -1439.3  |proj g|=        1.3524
## At iterate    30  f =      -1439.7  |proj g|=       0.15733
## At iterate    40  f =      -1439.7  |proj g|=        2.2855
## At iterate    50  f =      -1439.7  |proj g|=     0.0049361
## 
## iterations 51
## function evaluations 65
## segments explored during Cauchy searches 54
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00493616
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749554 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 7/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1042.7  |proj g|=           20
## At iterate    10  f =      -1436.9  |proj g|=        3.8025
## At iterate    20  f =      -1439.6  |proj g|=       0.92406
## At iterate    30  f =      -1439.7  |proj g|=       0.10271
## At iterate    40  f =      -1439.7  |proj g|=       0.41089
## 
## iterations 46
## function evaluations 66
## segments explored during Cauchy searches 51
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00399233
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749556 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 8/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -342.03  |proj g|=           14
## At iterate    10  f =      -1437.8  |proj g|=        7.2792
## At iterate    20  f =      -1439.6  |proj g|=        1.0885
## 
## iterations 28
## function evaluations 34
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0214284
## final function value -1439.73
## 
## F = -1439.73
## final  value -1439.728569 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 9/9
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1064.9  |proj g|=           20
## At iterate    10  f =      -1439.3  |proj g|=        5.1724
## At iterate    20  f =      -1439.6  |proj g|=        2.1779
## At iterate    30  f =      -1439.7  |proj g|=      0.019705
## At iterate    40  f =      -1439.7  |proj g|=       0.21147
## 
## iterations 43
## function evaluations 52
## segments explored during Cauchy searches 47
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0131519
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.749543 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
print(est.denver.model.3.4)
## Optimisation for STmodel with 9 starting points.
##   Results: 0 converged, 9 not converged, 0 failed.
##   Best result for starting point 2, optimisation has NOT converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0103798820   0.0137645059   0.0137643515
## alpha.const.(Intercept)           0.1847431546   0.0437529529   0.0437565813
## alpha.const.impervious_2500       0.0063270487   0.0578198129   0.0578204659
## alpha.const.open_2500            -0.0120291094   0.0185569852   0.0185573461
## alpha.const.low_int_100           0.0232715703   0.0175863570   0.0175869791
## alpha.const.med_int_50            0.0217494348   0.0003318879   0.0003316137
## alpha.const.high_int_50           0.0070875292   0.0077460211   0.0077461838
## alpha.const.high_int_100          0.0137296326   0.0010228311   0.0010225732
## alpha.const.ag_250                0.0031352343   0.0003663657   0.0003662982
## alpha.const.pop_den_50            0.0053467838  -0.0006127786  -0.0006130659
## alpha.const.dist_m_compost        0.0077416454  -0.0021466072  -0.0021466663
## alpha.const.dist_m_military       0.0119561822   0.0016950428   0.0016948086
## alpha.const.len_m_highways_2500  -0.0123435458   0.0013803980   0.0013801527
## alpha.const.aadt_100              0.0201345562   0.0258027137   0.0258030957
## alpha.const.aadt_2500             0.0056895818  -0.0084602085  -0.0084603858
## alpha.V1.(Intercept)             -0.1957480561  -0.1502161217  -0.1502160658
## alpha.V1.impervious_2500         -0.0120228579  -0.0401464085  -0.0401464075
## alpha.V1.open_2500               -0.0266898581  -0.0378673897  -0.0378669605
## alpha.V1.low_int_100             -0.0137077438  -0.0066607988  -0.0066612060
## alpha.V1.med_int_50              -0.0187107494   0.0002556835   0.0002557594
## alpha.V1.high_int_50             -0.0036417330   0.0145127658   0.0145126064
## alpha.V1.high_int_100             0.0053290261  -0.0151905450  -0.0151899302
## alpha.V1.ag_250                   0.0082784141   0.0095441301   0.0095445094
## alpha.V1.pop_den_50              -0.0149124837  -0.0098731000  -0.0098725380
## alpha.V1.dist_m_compost          -0.0217656248  -0.0178635527  -0.0178628245
## alpha.V1.dist_m_military         -0.0061700685  -0.0059049642  -0.0059047717
## alpha.V1.len_m_highways_2500      0.0078118200  -0.0011995204  -0.0011993844
## alpha.V1.aadt_100                 0.0194422001   0.0290010530   0.0290011431
## alpha.V1.aadt_2500                0.0008089082   0.0118680622   0.0118680710
## log.nugget.const.iid            -14.7356344267 -15.0000000000 -15.0000000000
## log.range.V1.exp                  0.0000000000   4.0205092815   4.0217761519
## log.sill.V1.exp                 -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.exp               -14.7545776717  -7.1477947365  -7.1473684337
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -4.3674423160  -2.9396012098  -2.9394943493
## nu.log.nugget.(Intercept).exp    -4.6061517581  -5.5005503729  -5.5006310531
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0137646753   0.0137634205   0.0137639599
## alpha.const.(Intercept)           0.0437490692   0.0437778247   0.0437655222
## alpha.const.impervious_2500       0.0577195818   0.0578175402   0.0578203500
## alpha.const.open_2500             0.0184636498   0.0185549350   0.0185573535
## alpha.const.low_int_100           0.0175142615   0.0175843298   0.0175866806
## alpha.const.med_int_50            0.0003283501   0.0003318642   0.0003317388
## alpha.const.high_int_50           0.0077312009   0.0077452116   0.0077459492
## alpha.const.high_int_100          0.0010426759   0.0010241222   0.0010229864
## alpha.const.ag_250                0.0003685224   0.0003663648   0.0003662993
## alpha.const.pop_den_50           -0.0005908245  -0.0006126824  -0.0006131537
## alpha.const.dist_m_compost       -0.0021290396  -0.0021457264  -0.0021464683
## alpha.const.dist_m_military       0.0017230544   0.0016961502   0.0016950528
## alpha.const.len_m_highways_2500   0.0014009845   0.0013815793   0.0013805091
## alpha.const.aadt_100              0.0257733841   0.0258021063   0.0258030175
## alpha.const.aadt_2500            -0.0084224836  -0.0084593895  -0.0084603816
## alpha.V1.(Intercept)             -0.1502218412  -0.1502228343  -0.1502187781
## alpha.V1.impervious_2500         -0.0400838823  -0.0401447561  -0.0401463848
## alpha.V1.open_2500               -0.0378063066  -0.0378662470  -0.0378672848
## alpha.V1.low_int_100             -0.0066113339  -0.0066595185  -0.0066610535
## alpha.V1.med_int_50               0.0002564538   0.0002557814   0.0002557647
## alpha.V1.high_int_50              0.0145199551   0.0145129120   0.0145126479
## alpha.V1.high_int_100            -0.0151992472  -0.0151910443  -0.0151902637
## alpha.V1.ag_250                   0.0095434442   0.0095436286   0.0095441754
## alpha.V1.pop_den_50              -0.0098871115  -0.0098739132  -0.0098729256
## alpha.V1.dist_m_compost          -0.0178747929  -0.0178640974  -0.0178631904
## alpha.V1.dist_m_military         -0.0059196761  -0.0059053046  -0.0059048257
## alpha.V1.len_m_highways_2500     -0.0012111942  -0.0011999505  -0.0011994870
## alpha.V1.aadt_100                 0.0290194419   0.0290014319   0.0290010737
## alpha.V1.aadt_2500                0.0118422782   0.0118675432   0.0118681251
## log.nugget.const.iid            -12.6524541311 -14.7838426054 -15.0000000000
## log.range.V1.exp                  4.0169713987   4.0189985914   4.0242571583
## log.sill.V1.exp                 -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.exp                -7.1504903963  -7.1483224919  -7.1477057902
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -2.9398729113  -2.9394543129  -2.9394661756
## nu.log.nugget.(Intercept).exp    -5.5006982997  -5.5005794252  -5.5006092436
##                                           [,7]           [,8]           [,9]
## gamma.bc_st_no2                   0.0137639898   0.0137645901   0.0137643469
## alpha.const.(Intercept)           0.0437648246   0.0437598413   0.0437566373
## alpha.const.impervious_2500       0.0578202477   0.0578147056   0.0578201278
## alpha.const.open_2500             0.0185572960   0.0185532617   0.0185571734
## alpha.const.low_int_100           0.0175865856   0.0175873232   0.0175866193
## alpha.const.med_int_50            0.0003317807   0.0003298952   0.0003317708
## alpha.const.high_int_50           0.0077459264   0.0077449940   0.0077460582
## alpha.const.high_int_100          0.0010230219   0.0010289336   0.0010227806
## alpha.const.ag_250                0.0003663100   0.0003665746   0.0003663309
## alpha.const.pop_den_50           -0.0006131068  -0.0006146935  -0.0006129452
## alpha.const.dist_m_compost       -0.0021464615  -0.0021474795  -0.0021465979
## alpha.const.dist_m_military       0.0016950867   0.0016914725   0.0016949706
## alpha.const.len_m_highways_2500   0.0013805433   0.0013831270   0.0013803426
## alpha.const.aadt_100              0.0258029578   0.0257992087   0.0258028961
## alpha.const.aadt_2500            -0.0084603534  -0.0084612493  -0.0084602994
## alpha.V1.(Intercept)             -0.1502187505  -0.1502942052  -0.1502166392
## alpha.V1.impervious_2500         -0.0401463853  -0.0401780042  -0.0401464030
## alpha.V1.open_2500               -0.0378673487  -0.0378829110  -0.0378672318
## alpha.V1.low_int_100             -0.0066609908  -0.0066540558  -0.0066609791
## alpha.V1.med_int_50               0.0002557525   0.0002372169   0.0002557240
## alpha.V1.high_int_50              0.0145126727   0.0144718971   0.0145126914
## alpha.V1.high_int_100            -0.0151903570  -0.0151061598  -0.0151902930
## alpha.V1.ag_250                   0.0095441196   0.0095445677   0.0095442597
## alpha.V1.pop_den_50              -0.0098730097  -0.0098610358  -0.0098728864
## alpha.V1.dist_m_compost          -0.0178633013  -0.0178532902  -0.0178632484
## alpha.V1.dist_m_military         -0.0059048556  -0.0058988384  -0.0059048752
## alpha.V1.len_m_highways_2500     -0.0011995072  -0.0011990027  -0.0011994705
## alpha.V1.aadt_100                 0.0290010603   0.0289281459   0.0290010858
## alpha.V1.aadt_2500                0.0118681229   0.0118691803   0.0118680775
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.range.V1.exp                  4.0244286481   4.0048939667   4.0255604859
## log.sill.V1.exp                 -15.0000000000 -10.8537298292 -15.0000000000
## log.nugget.V1.exp                -7.1477669799  -7.1706260145  -7.1477078360
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -2.9394814786  -2.9394964025  -2.9396064507
## nu.log.nugget.(Intercept).exp    -5.5005946266  -5.5005921477  -5.5006542438
## 
## Function value(s):
## [1] 1077.358 1439.750 1439.750 1439.731 1439.749 1439.750 1439.750 1439.729
## [9] 1439.750

8.4.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.3.4 <- createCV(denver.model.3.4, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.3.4 <- sapply(split(denver.model.3.4$obs$ID, Ind.cv.3.4), unique)
print(sapply(ID.cv.3.4, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.3.4)
## Ind.cv.3.4
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.3.4 <- apply(sapply(ID.cv.3.4,function(x) denver.model.3.4$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.3.4) <- denver.model.3.4$locations$ID
print(I.col.3.4)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.3.4$locations$long,
     denver.model.3.4$locations$lat,
     pch=23+floor(I.col.3.4/max(I.col.3.4)+.5), bg=I.col.3.4,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.3.4.cv <- coef(est.denver.model.3.4, pars="cov")[,c("par","init")]
x.init.3.4.cv

Run the model with cross validation.

est.denver.3.4.cv <- estimateCV(denver.model.3.4, x.init.3.4.cv, Ind.cv.3.4)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1297.6  |proj g|=       1.4645
## 
## iterations 7
## function evaluations 9
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 1.48862e-06
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.717671 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -310.45  |proj g|=           14
## At iterate    10  f =      -1295.8  |proj g|=        2.6437
## At iterate    20  f =      -1297.7  |proj g|=        0.4442
## 
## iterations 27
## function evaluations 45
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0540983
## final function value -1297.72
## 
## F = -1297.72
## l(0) > u(0).  No feasible solutionfinal  value -1297.717560 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1308.4  |proj g|=       2.0715
## 
## iterations 6
## function evaluations 9
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00700987
## final function value -1308.52
## 
## F = -1308.52
## final  value -1308.524926 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -310.85  |proj g|=           14
## At iterate    10  f =      -1306.4  |proj g|=        0.5405
## At iterate    20  f =      -1308.4  |proj g|=       0.73629
## At iterate    30  f =      -1308.5  |proj g|=     0.0083199
## 
## iterations 31
## function evaluations 42
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00831981
## final function value -1308.52
## 
## F = -1308.52
## final  value -1308.521179 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1315.6  |proj g|=       4.2177
## 
## iterations 8
## function evaluations 10
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 9.32914e-07
## final function value -1316.37
## 
## F = -1316.37
## final  value -1316.366724 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -311.1  |proj g|=           14
## At iterate    10  f =      -1314.4  |proj g|=       0.81736
## At iterate    20  f =      -1316.2  |proj g|=        1.5072
## At iterate    30  f =      -1316.4  |proj g|=     0.0053876
## 
## iterations 32
## function evaluations 48
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00676086
## final function value -1316.36
## 
## F = -1316.36
## final  value -1316.361854 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1271.9  |proj g|=       6.1012
## 
## iterations 7
## function evaluations 21
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0296455
## final function value -1272.02
## 
## F = -1272.02
## l(0) > u(0).  No feasible solutionfinal  value -1272.018082 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -297.08  |proj g|=           14
## At iterate    10  f =      -1269.2  |proj g|=        8.9673
## At iterate    20  f =      -1271.5  |proj g|=        1.2821
## At iterate    30  f =        -1272  |proj g|=        0.1164
## 
## iterations 31
## function evaluations 39
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0215191
## final function value -1272.01
## 
## F = -1272.01
## final  value -1272.008815 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1294.9  |proj g|=       3.6879
## 
## iterations 8
## function evaluations 19
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00971105
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.961399 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -305.67  |proj g|=           14
## At iterate    10  f =      -1291.8  |proj g|=        1.7387
## At iterate    20  f =      -1294.9  |proj g|=        1.3327
## 
## iterations 29
## function evaluations 38
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00399273
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.960432 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1322.6  |proj g|=       6.8614
## 
## iterations 7
## function evaluations 20
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0177955
## final function value -1322.71
## 
## F = -1322.71
## l(0) > u(0).  No feasible solutionfinal  value -1322.713793 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -315.1  |proj g|=           14
## At iterate    10  f =      -1319.2  |proj g|=        1.9972
## At iterate    20  f =      -1322.5  |proj g|=       0.26576
## At iterate    30  f =      -1322.7  |proj g|=        1.6062
## At iterate    40  f =      -1322.7  |proj g|=      0.049876
## 
## iterations 42
## function evaluations 57
## segments explored during Cauchy searches 45
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.032451
## final function value -1322.71
## 
## F = -1322.71
## l(0) > u(0).  No feasible solutionfinal  value -1322.713788 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1318.6  |proj g|=        2.992
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1318.868052 
## stopped after 8 iterations
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -307.48  |proj g|=           14
## At iterate    10  f =      -1317.2  |proj g|=        4.2502
## At iterate    20  f =      -1318.7  |proj g|=         3.847
## At iterate    30  f =      -1318.9  |proj g|=     0.0093823
## 
## iterations 31
## function evaluations 39
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00359445
## final function value -1318.87
## 
## F = -1318.87
## final  value -1318.867378 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1305.7  |proj g|=       1.9977
## 
## iterations 8
## function evaluations 12
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0723995
## final function value -1305.76
## 
## F = -1305.76
## final  value -1305.755419 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       -306.4  |proj g|=           14
## At iterate    10  f =      -1303.2  |proj g|=        0.8338
## At iterate    20  f =      -1305.4  |proj g|=        9.1985
## 
## iterations 28
## function evaluations 40
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0327099
## final function value -1305.74
## 
## F = -1305.74
## final  value -1305.742325 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1314.3  |proj g|=       5.6416
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1314.348928 
## stopped after 7 iterations
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -302.11  |proj g|=           14
## At iterate    10  f =      -1311.8  |proj g|=        1.0552
## At iterate    20  f =      -1314.2  |proj g|=       0.92494
## At iterate    30  f =      -1314.3  |proj g|=      0.072811
## At iterate    40  f =      -1314.3  |proj g|=      0.043987
## 
## iterations 43
## function evaluations 52
## segments explored during Cauchy searches 46
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.000475308
## final function value -1314.35
## 
## F = -1314.35
## final  value -1314.348927 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=        -1307  |proj g|=       4.4828
## 
## iterations 7
## function evaluations 10
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 2.70393e-05
## final function value -1307.05
## 
## F = -1307.05
## final  value -1307.047746 
## converged
## 
## Optimisation using starting value 2/2
## N = 7, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -302.63  |proj g|=           14
## At iterate    10  f =      -1304.2  |proj g|=       0.92707
## At iterate    20  f =      -1306.9  |proj g|=       0.94381
## 
## iterations 29
## function evaluations 36
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0477592
## final function value -1307.04
## 
## F = -1307.04
## final  value -1307.036798 
## converged
## 
print(est.denver.3.4.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 6 converged, 4 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv      eigen.min eigen.all.min
## 1  1297.718        TRUE FALSE -0.00013791869            NA
## 2  1308.525        TRUE  TRUE  0.00006600677            NA
## 3  1316.362        TRUE  TRUE  0.00003522721            NA
## 4  1272.018        TRUE  TRUE  0.00004391283            NA
## 5  1294.961        TRUE  TRUE  0.00006975668            NA
## 6  1322.714        TRUE  TRUE  0.00005987668            NA
## 7  1318.867        TRUE  TRUE  0.00007076740            NA
## 8  1305.755        TRUE FALSE -0.00029220981            NA
## 9  1314.349       FALSE FALSE  0.00003253930            NA
## 10 1307.048        TRUE FALSE -0.00013613958            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.3.4, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.3.4.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.1, denver.model.3.4, est.denver.model.3.4, est.denver.3.4.cv,
     file = here::here("Results", "Denver_ST_Model_3.4.rdata"))

8.4.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.3.4.cv <- predictCV(denver.model.3.4, est.denver.3.4.cv, LTA = T)
pred.3.4.cv.log <- predictCV(denver.model.3.4, est.denver.3.4.cv,
                             LTA = T, transform="unbiased")

names(pred.3.4.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.3.4.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.12790133  0.1280063 0.08538524
## average 0.07048871  0.0705859 0.05790838
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6147798  0.6141471 0.8283181
## average 0.7823811  0.7817806 0.8531275
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9222042
## average 0.8333333
summary(pred.3.4.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.15172126 0.15194616 0.09921391 0.09932602
## average 0.08379019 0.08399271 0.06539190 0.06575353
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6435598  0.6425023 0.8475811 0.8472364
## average 0.8110951  0.8101809 0.8849452 0.8836691
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9222042
## average 0.8333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.4.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.4.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod3.4.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.3.4.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.4.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

8.5 Model 3.5: Smoothing for beta fields and error term

8.5.1 Create the model object (exp covariance structure)

Now I’m using the exp covariance structure for cov.beta (beta0 and beta1) and cov.nu.

names(denver.data2.1$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR3.5<- list(covar_fun, covar_fun)

cov.beta3.5 <-  list(covf=c("exp", "exp"), nugget = c(TRUE, TRUE))
cov.nu3.5 <- list(covf="exp", nugget = T, random.effect = FALSE)
locations3.5 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.3.5 <- createSTmodel(denver.data2.1, LUR = LUR3.5,
                                  ST = "bc_st_no2",
                                  cov.beta = cov.beta3.5, cov.nu = cov.nu3.5,
                                  locations = locations3.5)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.3.5
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 1 basis function(s):
## [1] "V1"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 1 spatio-temporal covariate(s):
## [1] "bc_st_no2"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): exp, exp 
##  Nugget: Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

8.5.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.3.5, all=FALSE)
names
## [1] "log.range.const.exp"           "log.sill.const.exp"           
## [3] "log.nugget.const.exp"          "log.range.V1.exp"             
## [5] "log.sill.V1.exp"               "log.nugget.V1.exp"            
## [7] "nu.log.range.exp"              "nu.log.sill.exp"              
## [9] "nu.log.nugget.(Intercept).exp"
# x.init.3.5 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0),
#                     c(0, -1, -1, 0, -1, -1, 0, -1, -1),
#                     c(0, -1, -5, 0, -1, -5, 0, -1, -5),
#                     c(0, -5, -1, 0, -1, -1, 0, -1, -1),
#                     c(0, -5, -5, 0, -1, -5, 0, -1, -5),
#                     c(2, -1, -1, 2, -1, -1, 2, -1, -1),
#                     c(2, -1, -5, 2, -1, -5, 2, -1, -5),
#                     c(2, -5, -1, 2, -1, -1, 2, -1, -1),
#                     c(2, -5, -5, 2, -1, -5, 2, -1, -5),
#                     c(4, -1, -1, 4, -1, -1, 4, -1, -1),
#                     c(4, -1, -5, 4, -1, -5, 4, -1, -5),
#                     c(4, -5, -1, 4, -1, -1, 4, -1, -1),
#                     c(4, -5, -5, 4, -1, -5, 4, -1, -5),
#                     c(6, -1, -1, 6, -1, -1, 6, -1, -1),
#                     c(6, -1, -5, 6, -1, -5, 6, -1, -5),
#                     c(6, -5, -1, 6, -1, -1, 6, -1, -1),
#                     c(6, -5, -5, 6, -1, -5, 6, -1, -5)
#                     )

x.init.3.5 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0),
                    c(6, -10, -5, 4, -10, -5, 4, -1, -5),
                    c(6, -5, -1, 4, -10, -1, 4, -1, -1),
                    c(6, -5, -5, 4, -10, -5, 4, -1, -5),
                    c(8, -10, -10, 6, -10, -10, 10, -1, -1),
                    c(8, -10, -5, 6, -10, -5, 10, -1, -5),
                    c(8, -10, -10, 6, -10, -5, 10, -10, -5)
                    )

rownames(x.init.3.5) <- loglikeSTnames(denver.model.3.5, all=FALSE)
x.init.3.5
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## log.range.const.exp              0    6    6    6    8    8    8
## log.sill.const.exp               0  -10   -5   -5  -10  -10  -10
## log.nugget.const.exp             0   -5   -1   -5  -10   -5  -10
## log.range.V1.exp                 0    4    4    4    6    6    6
## log.sill.V1.exp                  0  -10  -10  -10  -10  -10  -10
## log.nugget.V1.exp                0   -5   -1   -5  -10   -5   -5
## nu.log.range.exp                 0    4    4    4   10   10   10
## nu.log.sill.exp                  0   -1   -1   -1   -1   -1  -10
## nu.log.nugget.(Intercept).exp    0   -5   -1   -5   -1   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.3.5 <- estimate.STmodel(denver.model.3.5, x.init.3.5)
## Optimisation using starting value 1/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       389.61  |proj g|=           15
## At iterate    10  f =      -1077.1  |proj g|=        4.0716
## At iterate    20  f =      -1077.4  |proj g|=        0.2336
## At iterate    30  f =      -1077.4  |proj g|=     0.0027895
## 
## iterations 30
## function evaluations 40
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0027895
## final function value -1077.36
## 
## F = -1077.36
## final  value -1077.356123 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -349.83  |proj g|=           14
## At iterate    10  f =      -1076.5  |proj g|=        3.9833
## ys=-1.348e+01  -gs= 6.612e-01, BFGS update SKIPPED
## At iterate    20  f =      -1095.4  |proj g|=        11.144
## At iterate    30  f =      -1431.4  |proj g|=        9.6528
## At iterate    40  f =      -1439.4  |proj g|=       0.83366
## At iterate    50  f =      -1439.7  |proj g|=      0.052426
## At iterate    60  f =      -1439.7  |proj g|=       0.31341
## 
## iterations 63
## function evaluations 84
## segments explored during Cauchy searches 64
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0141241
## final function value -1439.74
## 
## F = -1439.74
## final  value -1439.743011 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -15.366  |proj g|=           14
## At iterate    10  f =      -1076.6  |proj g|=        1.2579
## At iterate    20  f =      -1077.3  |proj g|=       0.12884
## ys=-4.253e+01  -gs= 8.368e+01, BFGS update SKIPPED
## At iterate    30  f =      -1310.6  |proj g|=        19.016
## At iterate    40  f =      -1395.3  |proj g|=       0.22108
## At iterate    50  f =      -1436.5  |proj g|=        1.9387
## At iterate    60  f =      -1436.7  |proj g|=       0.45553
## ys=-8.943e-03  -gs= 6.558e-02, BFGS update SKIPPED
## At iterate    70  f =      -1437.1  |proj g|=        4.4315
## At iterate    80  f =      -1439.7  |proj g|=       0.49749
## At iterate    90  f =      -1439.7  |proj g|=      0.078385
## At iterate   100  f =      -1439.7  |proj g|=        0.2128
## 
## iterations 103
## function evaluations 141
## segments explored during Cauchy searches 107
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.243147
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.747342 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -346.15  |proj g|=           14
## At iterate    10  f =      -1075.9  |proj g|=        1.6752
## At iterate    20  f =      -1077.3  |proj g|=       0.19867
## ys=-8.784e+00  -gs= 1.194e+02, BFGS update SKIPPED
## At iterate    30  f =      -1365.6  |proj g|=        18.739
## At iterate    40  f =      -1395.6  |proj g|=        1.8021
## At iterate    50  f =      -1436.6  |proj g|=      0.014693
## ys=-1.482e-01  -gs= 2.291e-02, BFGS update SKIPPED
## At iterate    60  f =      -1437.6  |proj g|=        8.4081
## At iterate    70  f =      -1439.7  |proj g|=        1.1231
## At iterate    80  f =      -1439.7  |proj g|=      0.073304
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 82
## function evaluations 152
## segments explored during Cauchy searches 84
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0456395
## final function value -1439.75
## 
## F = -1439.75
## l(0) > u(0).  No feasible solutionfinal  value -1439.747046 
## converged
## Optimisation using starting value 5/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=         -204  |proj g|=           14
## At iterate    10  f =      -1436.6  |proj g|=        13.355
## At iterate    20  f =      -1439.4  |proj g|=        4.6951
## At iterate    30  f =      -1439.7  |proj g|=       0.04314
## 
## iterations 34
## function evaluations 49
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0158565
## final function value -1439.74
## 
## F = -1439.74
## l(0) > u(0).  No feasible solutionfinal  value -1439.744785 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -718.54  |proj g|=           14
## At iterate    10  f =      -1437.1  |proj g|=        4.5902
## At iterate    20  f =      -1439.6  |proj g|=       0.88551
## At iterate    30  f =      -1439.7  |proj g|=        0.7039
## At iterate    40  f =      -1439.7  |proj g|=      0.029586
## 
## iterations 40
## function evaluations 58
## segments explored during Cauchy searches 44
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0295862
## final function value -1439.75
## 
## F = -1439.75
## l(0) > u(0).  No feasible solutionfinal  value -1439.745607 
## converged
## Optimisation using starting value 7/7
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -688.53  |proj g|=           25
## At iterate    10  f =      -1435.6  |proj g|=        11.905
## At iterate    20  f =      -1439.7  |proj g|=       0.51273
## At iterate    30  f =      -1439.7  |proj g|=      0.051161
## At iterate    40  f =      -1439.7  |proj g|=      0.020693
## 
## iterations 41
## function evaluations 55
## segments explored during Cauchy searches 45
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.015372
## final function value -1439.75
## 
## F = -1439.75
## final  value -1439.748689 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
print(est.denver.model.3.5)
## Optimisation for STmodel with 7 starting points.
##   Results: 2 converged, 5 not converged, 0 failed.
##   Best result for starting point 7, optimisation has NOT converged
##   Best converged result for starting point 4 
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.0103799744   0.0137636871   0.0137500668
## alpha.const.(Intercept)           0.1847401078   0.0437683755   0.0440784381
## alpha.const.impervious_2500       0.0063212844   0.0578093416   0.0578138441
## alpha.const.open_2500            -0.0120348538   0.0185476203   0.0185524907
## alpha.const.low_int_100           0.0232657681   0.0175793373   0.0175765307
## alpha.const.med_int_50            0.0217491023   0.0003299875   0.0003313234
## alpha.const.high_int_50           0.0070855171   0.0077433207   0.0077380946
## alpha.const.high_int_100          0.0137308301   0.0010280538   0.0010365863
## alpha.const.ag_250                0.0031350746   0.0003664473   0.0003657076
## alpha.const.pop_den_50            0.0053494185  -0.0006108310  -0.0006160737
## alpha.const.dist_m_compost        0.0077426850  -0.0021444042  -0.0021387411
## alpha.const.dist_m_military       0.0119590564   0.0016971231   0.0017029184
## alpha.const.len_m_highways_2500  -0.0123420048   0.0013843540   0.0013920756
## alpha.const.aadt_100              0.0201331688   0.0257981008   0.0258005266
## alpha.const.aadt_2500             0.0056927388  -0.0084566936  -0.0084581942
## alpha.V1.(Intercept)             -0.1957472061  -0.1502356054  -0.1503002164
## alpha.V1.impervious_2500         -0.0120194278  -0.0401478780  -0.0401399495
## alpha.V1.open_2500               -0.0266860801  -0.0378651864  -0.0378670127
## alpha.V1.low_int_100             -0.0137038949  -0.0066544367  -0.0066556199
## alpha.V1.med_int_50              -0.0187108165   0.0002521100   0.0002573339
## alpha.V1.high_int_50             -0.0036416790   0.0145042260   0.0145131934
## alpha.V1.high_int_100             0.0053301534  -0.0151722986  -0.0151953902
## alpha.V1.ag_250                   0.0082790280   0.0095441909   0.0095378795
## alpha.V1.pop_den_50              -0.0149138542  -0.0098717395  -0.0098804184
## alpha.V1.dist_m_compost          -0.0217655207  -0.0178620024  -0.0178678712
## alpha.V1.dist_m_military         -0.0061710830  -0.0059049137  -0.0059059579
## alpha.V1.len_m_highways_2500      0.0078108237  -0.0012007116  -0.0012025213
## alpha.V1.aadt_100                 0.0194423039   0.0289865144   0.0290020747
## alpha.V1.aadt_2500                0.0008069388   0.0118656934   0.0118671684
## log.range.const.exp               0.0000000000   6.2384653114   6.3146253407
## log.sill.const.exp              -14.7544496149 -15.0000000000 -15.0000000000
## log.nugget.const.exp            -14.6552407487 -15.0000000000 -15.0000000000
## log.range.V1.exp                  0.0000000000   4.0121700088   4.3623584626
## log.sill.V1.exp                 -15.0000000000 -12.2753797508 -15.0000000000
## log.nugget.V1.exp               -15.0000000000  -7.1532548408  -7.1528104717
## nu.log.range.exp                  0.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -4.3670390628  -2.9394307974  -2.9363998696
## nu.log.nugget.(Intercept).exp    -4.6066413077  -5.5006655045  -5.4997725414
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0137637169   0.0137634563   0.0137621833
## alpha.const.(Intercept)           0.0437657587   0.0437631605   0.0438073151
## alpha.const.impervious_2500       0.0578072763   0.0577652018   0.0578182700
## alpha.const.open_2500             0.0185450515   0.0185198052   0.0185559084
## alpha.const.low_int_100           0.0175770598   0.0175492537   0.0175855026
## alpha.const.med_int_50            0.0003299872   0.0003200894   0.0003309500
## alpha.const.high_int_50           0.0077433544   0.0077274681   0.0077445799
## alpha.const.high_int_100          0.0010266782   0.0010451262   0.0010253018
## alpha.const.ag_250                0.0003664217   0.0003615770   0.0003659743
## alpha.const.pop_den_50           -0.0006097730  -0.0005977709  -0.0006135742
## alpha.const.dist_m_compost       -0.0021436972  -0.0021287333  -0.0021446566
## alpha.const.dist_m_military       0.0016987268   0.0017152883   0.0016967378
## alpha.const.len_m_highways_2500   0.0013839475   0.0014126885   0.0013830147
## alpha.const.aadt_100              0.0257983464   0.0257877389   0.0258027889
## alpha.const.aadt_2500            -0.0084550885  -0.0084471888  -0.0084602834
## alpha.V1.(Intercept)             -0.1502164329  -0.1502196783  -0.1502439464
## alpha.V1.impervious_2500         -0.0401386832  -0.0401262634  -0.0401536486
## alpha.V1.open_2500               -0.0378586545  -0.0378427465  -0.0378696245
## alpha.V1.low_int_100             -0.0066547656  -0.0066433222  -0.0066605719
## alpha.V1.med_int_50               0.0002564465   0.0002609357   0.0002529602
## alpha.V1.high_int_50              0.0145135067   0.0145161931   0.0145041232
## alpha.V1.high_int_100            -0.0151909335  -0.0151967809  -0.0151744022
## alpha.V1.ag_250                   0.0095445924   0.0095395275   0.0095432890
## alpha.V1.pop_den_50              -0.0098737441  -0.0098776535  -0.0098680876
## alpha.V1.dist_m_compost          -0.0178635547  -0.0178664625  -0.0178599145
## alpha.V1.dist_m_military         -0.0059068704  -0.0059146513  -0.0059047983
## alpha.V1.len_m_highways_2500     -0.0012003202  -0.0012024770  -0.0011947752
## alpha.V1.aadt_100                 0.0290040798   0.0290075252   0.0289873581
## alpha.V1.aadt_2500                0.0118642949   0.0118607890   0.0118680886
## log.range.const.exp               6.1809934952   9.8525307460  11.4520943248
## log.sill.const.exp              -15.0000000000 -13.1305211383 -15.0000000000
## log.nugget.const.exp            -14.6706337195 -15.0000000000 -15.0000000000
## log.range.V1.exp                  6.1934277712   4.8441832341   5.6288068791
## log.sill.V1.exp                 -15.0000000000 -14.7919989580 -12.4352760821
## log.nugget.V1.exp                -7.1472190450  -7.1488236815  -7.1525413865
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -2.9390721554  -2.9395228996  -2.9390744608
## nu.log.nugget.(Intercept).exp    -5.5004740408  -5.5005670107  -5.5006159054
##                                           [,7]
## gamma.bc_st_no2                   0.0137638372
## alpha.const.(Intercept)           0.0437667238
## alpha.const.impervious_2500       0.0578153739
## alpha.const.open_2500             0.0185540162
## alpha.const.low_int_100           0.0175828702
## alpha.const.med_int_50            0.0003303885
## alpha.const.high_int_50           0.0077438254
## alpha.const.high_int_100          0.0010253402
## alpha.const.ag_250                0.0003656891
## alpha.const.pop_den_50           -0.0006114800
## alpha.const.dist_m_compost       -0.0021439052
## alpha.const.dist_m_military       0.0016981735
## alpha.const.len_m_highways_2500   0.0013841277
## alpha.const.aadt_100              0.0258015945
## alpha.const.aadt_2500            -0.0084591194
## alpha.V1.(Intercept)             -0.1502198161
## alpha.V1.impervious_2500         -0.0401452074
## alpha.V1.open_2500               -0.0378649263
## alpha.V1.low_int_100             -0.0066595115
## alpha.V1.med_int_50               0.0002561685
## alpha.V1.high_int_50              0.0145123681
## alpha.V1.high_int_100            -0.0151896228
## alpha.V1.ag_250                   0.0095437714
## alpha.V1.pop_den_50              -0.0098725958
## alpha.V1.dist_m_compost          -0.0178627999
## alpha.V1.dist_m_military         -0.0059058685
## alpha.V1.len_m_highways_2500     -0.0011989154
## alpha.V1.aadt_100                 0.0290008855
## alpha.V1.aadt_2500                0.0118673401
## log.range.const.exp              10.3819095425
## log.sill.const.exp              -15.0000000000
## log.nugget.const.exp            -15.0000000000
## log.range.V1.exp                  5.8035802937
## log.sill.V1.exp                 -14.4249986220
## log.nugget.V1.exp                -7.1478593336
## nu.log.range.exp                 15.0000000000
## nu.log.sill.exp                  -2.9393479978
## nu.log.nugget.(Intercept).exp    -5.5005653317
## 
## Function value(s):
## [1] 1077.356 1439.743 1439.747 1439.747 1439.745 1439.746 1439.749

8.5.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs))
##  [1] "central" "d_2"     "d_4"     "d_6"     "d_12"    "d_14"    "d_16"   
##  [8] "d_18"    "d_20"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_8"     "d_11"    "d_13"    "d_15"    "d_17"    "d_19"    "d_21"   
## [22] "d_23"    "d_25"    "d_3"     "d_10"    "d_28"    "d_30"    "d_32"   
## [29] "d_34"    "d_36"    "d_38"    "d_40"    "d_41"    "d_42"    "d_43"   
## [36] "d_44"    "d_45"    "d_1"     "d_9"     "d_27"    "d_29"    "d_31"   
## [43] "d_33"    "d_37"    "d_39"    "d_35"    "d_49"    "d_51"    "d_52"   
## [50] "d_55"    "d_56"    "d_46"    "d_47"    "d_50"    "d_53"    "d_54"   
## [57] "d_48"    "d_58"    "d_59"    "d_60"    "d_57"
Ind.cv.3.5 <- createCV(denver.model.3.5, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.3.5 <- sapply(split(denver.model.3.5$obs$ID, Ind.cv.3.5), unique)
print(sapply(ID.cv.3.5, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.3.5)
## Ind.cv.3.5
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.3.5 <- apply(sapply(ID.cv.3.5,function(x) denver.model.3.5$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.3.5) <- denver.model.3.5$locations$ID
print(I.col.3.5)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.3.5$locations$long,
     denver.model.3.5$locations$lat,
     pch=23+floor(I.col.3.5/max(I.col.3.5)+.5), bg=I.col.3.5,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.3.5.cv <- coef(est.denver.model.3.5, pars="cov")[,c("par","init")]
x.init.3.5.cv

Run the model with cross validation.

est.denver.3.5.cv <- estimateCV(denver.model.3.5, x.init.3.5.cv, Ind.cv.3.5)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1297.6  |proj g|=       1.4494
## 
## iterations 6
## function evaluations 8
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0019581
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.715890 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -317.26  |proj g|=           14
## At iterate    10  f =      -975.56  |proj g|=        1.3973
## At iterate    20  f =      -976.49  |proj g|=       0.76208
## At iterate    30  f =      -1252.6  |proj g|=        3.9208
## At iterate    40  f =      -1290.4  |proj g|=         18.22
## At iterate    50  f =      -1294.3  |proj g|=       0.36664
## ys=-2.850e-04  -gs= 1.532e-03, BFGS update SKIPPED
## At iterate    60  f =      -1295.2  |proj g|=        3.7942
## At iterate    70  f =      -1297.7  |proj g|=       0.71135
## At iterate    80  f =      -1297.7  |proj g|=     0.0089466
## At iterate    90  f =      -1297.7  |proj g|=       0.32804
## 
## iterations 95
## function evaluations 127
## segments explored during Cauchy searches 96
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.00025263
## final function value -1297.72
## 
## F = -1297.72
## final  value -1297.716439 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1308.4  |proj g|=       2.0844
## 
## iterations 6
## function evaluations 9
## segments explored during Cauchy searches 6
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0057317
## final function value -1308.52
## 
## F = -1308.52
## final  value -1308.523300 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -318.63  |proj g|=           14
## At iterate    10  f =      -979.52  |proj g|=        1.0318
## At iterate    20  f =      -980.24  |proj g|=        4.8618
## ys=-7.548e+00  -gs= 8.286e+01, BFGS update SKIPPED
## At iterate    30  f =      -1258.9  |proj g|=        14.251
## At iterate    40  f =      -1275.4  |proj g|=       0.35076
## At iterate    50  f =      -1307.8  |proj g|=       0.45487
## At iterate    60  f =      -1308.5  |proj g|=        0.6819
## 
## iterations 67
## function evaluations 102
## segments explored during Cauchy searches 68
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0299828
## final function value -1308.52
## 
## F = -1308.52
## l(0) > u(0).  No feasible solutionfinal  value -1308.516933 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1315.6  |proj g|=       4.2278
## 
## iterations 8
## function evaluations 12
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00549139
## final function value -1316.36
## 
## F = -1316.36
## final  value -1316.364386 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -319.85  |proj g|=           14
## At iterate    10  f =      -985.91  |proj g|=        1.9457
## At iterate    20  f =      -986.74  |proj g|=        1.0694
## ys=-3.688e+01  -gs= 8.062e-01, BFGS update SKIPPED
## At iterate    30  f =      -1277.8  |proj g|=        12.124
## At iterate    40  f =      -1290.8  |proj g|=        0.8737
## At iterate    50  f =      -1315.7  |proj g|=        1.4041
## At iterate    60  f =      -1316.3  |proj g|=        3.3417
## 
## iterations 66
## function evaluations 104
## segments explored during Cauchy searches 67
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0620716
## final function value -1316.35
## 
## F = -1316.35
## l(0) > u(0).  No feasible solutionfinal  value -1316.345234 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1271.9  |proj g|=       6.0705
## 
## iterations 7
## function evaluations 18
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0264747
## final function value -1272.02
## 
## F = -1272.02
## final  value -1272.016134 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -312.14  |proj g|=           14
## At iterate    10  f =      -950.54  |proj g|=        2.8319
## At iterate    20  f =      -987.01  |proj g|=        11.189
## ys=-1.573e+02  -gs= 6.005e-01, BFGS update SKIPPED
## At iterate    30  f =      -1271.1  |proj g|=        5.0485
## At iterate    40  f =        -1272  |proj g|=       0.49588
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 45
## function evaluations 91
## segments explored during Cauchy searches 47
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0137092
## final function value -1272.01
## 
## F = -1272.01
## final  value -1272.012823 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1294.9  |proj g|=       3.6618
## 
## iterations 8
## function evaluations 17
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00740456
## final function value -1294.96
## 
## F = -1294.96
## final  value -1294.956988 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -316.17  |proj g|=           14
## At iterate    10  f =         -971  |proj g|=        6.0097
## At iterate    20  f =      -972.45  |proj g|=       0.10834
## ys=-1.312e-01  -gs= 1.325e-01, BFGS update SKIPPED
## ys=-1.353e+02  -gs= 2.132e+00, BFGS update SKIPPED
## At iterate    30  f =      -1094.9  |proj g|=        21.754
## At iterate    40  f =      -1260.6  |proj g|=        1.6704
## At iterate    50  f =      -1291.3  |proj g|=        13.084
## At iterate    60  f =      -1293.6  |proj g|=        2.5703
## At iterate    70  f =      -1294.9  |proj g|=       0.62665
## At iterate    80  f =      -1294.9  |proj g|=       0.28509
## At iterate    90  f =        -1295  |proj g|=      0.049547
## 
## iterations 90
## function evaluations 132
## segments explored during Cauchy searches 91
## BFGS updates skipped 2
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0495468
## final function value -1294.96
## 
## F = -1294.96
## l(0) > u(0).  No feasible solutionfinal  value -1294.956574 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1322.6  |proj g|=        6.833
## 
## iterations 7
## function evaluations 19
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0183625
## final function value -1322.71
## 
## F = -1322.71
## l(0) > u(0).  No feasible solutionfinal  value -1322.709710 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -323.14  |proj g|=           14
## At iterate    10  f =      -993.06  |proj g|=       0.54664
## At iterate    20  f =      -993.74  |proj g|=       0.84507
## At iterate    30  f =      -1252.6  |proj g|=        12.301
## At iterate    40  f =      -1319.2  |proj g|=        5.2369
## ys=-1.079e-02  -gs= 5.164e-03, BFGS update SKIPPED
## At iterate    50  f =      -1319.6  |proj g|=       0.95686
## At iterate    60  f =      -1319.6  |proj g|=        1.5866
## 
## iterations 65
## function evaluations 84
## segments explored during Cauchy searches 66
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0860235
## final function value -1319.64
## 
## F = -1319.64
## final  value -1319.639165 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1318.6  |proj g|=       2.9628
## 
## iterations 9
## function evaluations 12
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00196586
## final function value -1318.87
## 
## F = -1318.87
## final  value -1318.866316 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -313.48  |proj g|=           14
## At iterate    10  f =      -987.17  |proj g|=       0.23403
## ys=-1.332e+02  -gs= 2.659e+00, BFGS update SKIPPED
## At iterate    20  f =      -1316.9  |proj g|=       0.88296
## At iterate    30  f =      -1318.7  |proj g|=        1.7612
## At iterate    40  f =      -1318.9  |proj g|=      0.079576
## 
## iterations 40
## function evaluations 54
## segments explored during Cauchy searches 41
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0795763
## final function value -1318.87
## 
## F = -1318.87
## final  value -1318.865719 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1305.7  |proj g|=       1.9683
## 
## iterations 9
## function evaluations 14
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0569554
## final function value -1305.75
## 
## F = -1305.75
## final  value -1305.753217 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -318.46  |proj g|=           14
## At iterate    10  f =      -980.42  |proj g|=        10.574
## ys=-6.779e-02  -gs= 1.874e-01, BFGS update SKIPPED
## ys=-4.627e+00  -gs= 2.537e+00, BFGS update SKIPPED
## At iterate    20  f =      -1047.6  |proj g|=        10.871
## ys=-1.088e+00  -gs= 2.784e+01, BFGS update SKIPPED
## At iterate    30  f =      -1304.8  |proj g|=        1.5933
## At iterate    40  f =      -1305.7  |proj g|=      0.026889
## 
## iterations 41
## function evaluations 67
## segments explored during Cauchy searches 42
## BFGS updates skipped 3
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0268894
## final function value -1305.75
## 
## F = -1305.75
## l(0) > u(0).  No feasible solutionfinal  value -1305.748336 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=      -1314.3  |proj g|=       5.6119
## 
## iterations 8
## function evaluations 10
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00618947
## final function value -1314.35
## 
## F = -1314.35
## final  value -1314.346414 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -320.93  |proj g|=           14
## At iterate    10  f =      -985.39  |proj g|=        2.5782
## At iterate    20  f =      -986.07  |proj g|=      0.075083
## ys=-1.161e+00  -gs= 7.988e-02, BFGS update SKIPPED
## At iterate    30  f =      -1005.7  |proj g|=         22.44
## At iterate    40  f =        -1314  |proj g|=        5.8396
## 
## iterations 46
## function evaluations 70
## segments explored during Cauchy searches 47
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.119271
## final function value -1314.34
## 
## F = -1314.34
## final  value -1314.338306 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 3 variables are exactly at the bounds
## At iterate     0  f=        -1307  |proj g|=       4.5116
## 
## iterations 7
## function evaluations 11
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00349312
## final function value -1307.05
## 
## F = -1307.05
## final  value -1307.045320 
## converged
## 
## Optimisation using starting value 2/2
## N = 9, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -317.84  |proj g|=           14
## At iterate    10  f =      -980.13  |proj g|=         3.936
## At iterate    20  f =      -981.24  |proj g|=       0.13059
## At iterate    30  f =      -1081.5  |proj g|=        20.678
## At iterate    40  f =      -1290.8  |proj g|=         18.34
## At iterate    50  f =      -1304.3  |proj g|=        3.5296
## At iterate    60  f =      -1306.7  |proj g|=        6.4884
## At iterate    70  f =        -1307  |proj g|=       0.22455
## 
## iterations 76
## function evaluations 127
## segments explored during Cauchy searches 77
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0949673
## final function value -1307.05
## 
## F = -1307.05
## l(0) > u(0).  No feasible solutionfinal  value -1307.045561 
## converged
## 
print(est.denver.3.5.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 9 converged, 1 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv      eigen.min eigen.all.min
## 1  1297.716        TRUE  TRUE  0.00019702424            NA
## 2  1308.523        TRUE  TRUE  0.00022765073            NA
## 3  1316.364        TRUE  TRUE  0.00018770798            NA
## 4  1272.016        TRUE  TRUE  0.00015921232            NA
## 5  1294.957        TRUE  TRUE  0.00021513298            NA
## 6  1322.710        TRUE  TRUE  0.00023064209            NA
## 7  1318.866        TRUE FALSE -0.00012910285            NA
## 8  1305.753        TRUE  TRUE  0.00011297357            NA
## 9  1314.346        TRUE  TRUE  0.00009048147            NA
## 10 1307.046        TRUE  TRUE  0.00002093633            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.3.5, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.3.5.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data2.1, denver.model.3.5, est.denver.model.3.5, est.denver.3.5.cv,
     file = here::here("Results", "Denver_ST_Model_3.5.rdata"))

8.5.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.3.5.cv <- predictCV(denver.model.3.5, est.denver.3.5.cv, LTA = T)
pred.3.5.cv.log <- predictCV(denver.model.3.5, est.denver.3.5.cv,
                             LTA = T, transform="unbiased")

names(pred.3.5.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.3.5.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.12790195 0.12790166 0.08531153
## average 0.07048829 0.07048774 0.05786807
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6147760  0.6147778 0.8286144
## average 0.7823837  0.7823871 0.8533320
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9238250
## average 0.8333333
summary(pred.3.5.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.15172220  0.1517220 0.09902484 0.09914044
## average 0.08379005  0.0837896 0.06528119 0.06564901
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.6435554  0.6435563 0.8481614 0.8478067
## average 0.8110957  0.8110978 0.8853344 0.8840386
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9238250
## average 0.8333333
par(mfrow=c(1,2), mar=c(3.3,3.3,3.5,1), mgp=c(2,1,0))
plot(pred.3.5.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.5.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod3.5.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,3.5,1), mgp=c(2,1,0))
plot(pred.3.5.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.3.5.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

9 Updated models (NO2 + BC, two basis functions, binary smoke indicator)

The models above only use one ST predictor (NO2 estimated at each sampling location using IDW). In this next set of models, I am adding a binary indicator for smoke to see it fit improves models fit.

The smoke indicator is based on the methodology in the BC-wildfires paper, which is a modification of the methods used in Brey and Fischer (2016).

9.1 New data object with the additional ST covariate

denver.data4 <- createSTdata(obs = bc_obs2,
                             covars = bc_sp_cov,
                             SpatioTemporal = list(bc_st_no2 = bc_st_no22,
                                                   bc_st_smk = bc_st_smk2))
D4 <- createDataMatrix(denver.data4)
denver.data4
## STdata-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 155 (observed: 155)
##  No. obs: 772
## 
## Only constant temporal trend,with dates:
##  2016-02-08 to 2019-02-25
## 
## 19 covariate(s):
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"               
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

Add the two basis functions:

denver.data4.2 <- denver.data4
denver.data4.2$trend <- no2_bc_STdata2$trend
print(denver.data4.2)
## STdata-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## 19 covariate(s):
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"               
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

9.2 Model 4.1: simplest form

9.2.1 Create the model object

For this version of the model, use iid for both cov.beta (beta0, beta1, beta2) and cov.nu (error term). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data4.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR4.1 <- list(covar_fun, covar_fun, covar_fun)

cov.beta4.1 <-  list(covf="iid", nugget = T)
cov.nu4.1 <- list(covf="iid", nugget = T, random.effect = FALSE)
locations4.1 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.4.1 <- createSTmodel(denver.data4.2, LUR = LUR4.1,
                                  ST = c("bc_st_no2", "bc_st_smk"),
                                  cov.beta = cov.beta4.1, cov.nu = cov.nu4.1,
                                  locations = locations4.1)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.4.1
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, iid, iid 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: iid 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

9.2.2 Estimate model parameters

We want to try a number of initial conditions to make sure we find the “right” solution.

names <- loglikeSTnames(denver.model.4.1, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.nugget.V1.iid"            
## [3] "log.nugget.V2.iid"             "nu.log.nugget.(Intercept).iid"
# x.init.4.1 <- cbind(c(rep(-1, 4)), c(rep(-2, 4)), c(rep(-3, 4)),
#                     c(rep(-4, 4)), c(rep(-5, 4)), c(rep(-6, 4)))
# x.init.4.1[nrow(x.init.4.1),] <- 0

x.init.4.1 <- cbind(c(0, 0, 0),
                    c(-5, -5, -5, -5),
                    c(-8, -5, -5, -5),
                    c(-8, -8, -5, -5),
                    c(-8, -8, -8, -8))
## Warning in cbind(c(0, 0, 0), c(-5, -5, -5, -5), c(-8, -5, -5, -5), c(-8, :
## number of rows of result is not a multiple of vector length (arg 1)
rownames(x.init.4.1) <- loglikeSTnames(denver.model.4.1, all=FALSE)
x.init.4.1
##                               [,1] [,2] [,3] [,4] [,5]
## log.nugget.const.iid             0   -5   -8   -8   -8
## log.nugget.V1.iid                0   -5   -5   -8   -8
## log.nugget.V2.iid                0   -5   -5   -5   -8
## nu.log.nugget.(Intercept).iid    0   -5   -5   -5   -8
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.4.1 <- estimate.STmodel(denver.model.4.1, x.init.4.1)
## Optimisation using starting value 1/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       141.01  |proj g|=           15
## At iterate    10  f =      -1342.1  |proj g|=         4.696
## At iterate    20  f =      -1343.2  |proj g|=        1.0857
## 
## iterations 24
## function evaluations 41
## segments explored during Cauchy searches 27
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0135451
## final function value -1343.19
## 
## F = -1343.19
## l(0) > u(0).  No feasible solutionfinal  value -1343.188596 
## converged
## Optimisation using starting value 2/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1242.9  |proj g|=           20
## At iterate    10  f =      -1342.5  |proj g|=        2.8458
## At iterate    20  f =      -1343.1  |proj g|=      0.024758
## At iterate    30  f =      -1343.1  |proj g|=         2.627
## At iterate    40  f =      -1343.2  |proj g|=      0.066087
## 
## iterations 40
## function evaluations 63
## segments explored during Cauchy searches 43
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0660868
## final function value -1343.19
## 
## F = -1343.19
## l(0) > u(0).  No feasible solutionfinal  value -1343.188858 
## converged
## Optimisation using starting value 3/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1266.7  |proj g|=           20
## At iterate    10  f =      -1342.2  |proj g|=        5.1415
## At iterate    20  f =      -1343.2  |proj g|=      0.041473
## 
## iterations 25
## function evaluations 34
## segments explored during Cauchy searches 27
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0261373
## final function value -1343.19
## 
## F = -1343.19
## final  value -1343.188843 
## converged
## Optimisation using starting value 4/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1281.5  |proj g|=           20
## At iterate    10  f =      -1342.1  |proj g|=       0.75366
## At iterate    20  f =      -1343.2  |proj g|=       0.34006
## 
## iterations 27
## function evaluations 35
## segments explored during Cauchy searches 29
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00332728
## final function value -1343.19
## 
## F = -1343.19
## final  value -1343.188845 
## converged
## Optimisation using starting value 5/5
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=         8093  |proj g|=           23
## At iterate    10  f =      -1341.7  |proj g|=        3.1935
## At iterate    20  f =      -1343.2  |proj g|=     0.0088888
## 
## iterations 27
## function evaluations 60
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00127602
## final function value -1343.19
## 
## F = -1343.19
## l(0) > u(0).  No feasible solutionfinal  value -1343.188843 
## converged
print(est.denver.model.4.1)
## Optimisation for STmodel with 5 starting points.
##   Results: 5 converged, 0 not converged, 0 failed.
##   Best result for starting point 2, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                           [,1]            [,2]            [,3]
## gamma.bc_st_no2                   0.0135252983   0.01352317761   0.01352333314
## gamma.bc_st_smk                   0.0785139227   0.07851719072   0.07851689671
## alpha.const.(Intercept)           0.0653817857   0.06542135748   0.06541862518
## alpha.const.impervious_2500       0.0571247632   0.05707847409   0.05708230004
## alpha.const.open_2500             0.0200603301   0.02001480443   0.02001858032
## alpha.const.low_int_100           0.0094105184   0.00937839815   0.00938115308
## alpha.const.med_int_50            0.0045596031   0.00456517323   0.00456476504
## alpha.const.high_int_50           0.0178194011   0.01781952663   0.01781956175
## alpha.const.high_int_100         -0.0237014764  -0.02370416338  -0.02370397343
## alpha.const.ag_250               -0.0033344983  -0.00333926870  -0.00333892301
## alpha.const.pop_den_50            0.0032842031   0.00328564573   0.00328547933
## alpha.const.dist_m_compost        0.0055540243   0.00555356005   0.00555356480
## alpha.const.dist_m_military       0.0197381354   0.01974287506   0.01974230373
## alpha.const.len_m_highways_2500   0.0009905234   0.00099877285   0.00099799954
## alpha.const.aadt_100              0.0371772582   0.03716616152   0.03716718389
## alpha.const.aadt_2500            -0.0003838231  -0.00037450036  -0.00037529334
## alpha.V1.(Intercept)             -0.2805811612  -0.28060233403  -0.28060060442
## alpha.V1.impervious_2500         -0.0584378553  -0.05848323555  -0.05847895553
## alpha.V1.open_2500               -0.0425830831  -0.04262271052  -0.04261953915
## alpha.V1.low_int_100              0.0001097562   0.00009899039   0.00009989498
## alpha.V1.med_int_50              -0.0045910717  -0.00460703949  -0.00460570466
## alpha.V1.high_int_50              0.0094448677   0.00945560446   0.00945497573
## alpha.V1.high_int_100            -0.0335729556  -0.03359805532  -0.03359658395
## alpha.V1.ag_250                  -0.0086438688  -0.00869017598  -0.00868688122
## alpha.V1.pop_den_50              -0.0132238349  -0.01322575977  -0.01322596738
## alpha.V1.dist_m_compost          -0.0244638837  -0.02450244574  -0.02449966158
## alpha.V1.dist_m_military         -0.0128039580  -0.01283459096  -0.01283225870
## alpha.V1.len_m_highways_2500      0.0067712995   0.00677046564   0.00677005518
## alpha.V1.aadt_100                 0.0154439012   0.01540925551   0.01541266538
## alpha.V1.aadt_2500                0.0081739927   0.00815973092   0.00816082138
## alpha.V2.(Intercept)             -0.1275531622  -0.12757348660  -0.12757134680
## alpha.V2.impervious_2500         -0.0194941689  -0.01960644545  -0.01959600591
## alpha.V2.open_2500                0.0090229098   0.00892979341   0.00893778797
## alpha.V2.low_int_100              0.0042823927   0.00423540087   0.00423943701
## alpha.V2.med_int_50              -0.0049613415  -0.00497649708  -0.00497499267
## alpha.V2.high_int_50             -0.0082152702  -0.00821197322  -0.00821140683
## alpha.V2.high_int_100            -0.0363395942  -0.03635520366  -0.03635547698
## alpha.V2.ag_250                  -0.0264166476  -0.02646465493  -0.02646130127
## alpha.V2.pop_den_50               0.0030646106   0.00306364426   0.00306349507
## alpha.V2.dist_m_compost           0.0061783060   0.00614363395   0.00614597803
## alpha.V2.dist_m_military          0.0121521194   0.01212836633   0.01212987723
## alpha.V2.len_m_highways_2500      0.0144604085   0.01447735957   0.01447515516
## alpha.V2.aadt_100                 0.0009166872   0.00086556909   0.00087094459
## alpha.V2.aadt_2500                0.0004215325   0.00041710710   0.00041752276
## log.nugget.const.iid            -15.0000000000 -15.00000000000 -15.00000000000
## log.nugget.V1.iid                -8.6285788036  -8.67394976948  -8.66988211169
## log.nugget.V2.iid                -7.2828618348  -7.26308647144  -7.26520755776
## nu.log.nugget.(Intercept).iid    -4.5237945334  -4.52351019498  -4.52361980348
##                                            [,4]            [,5]
## gamma.bc_st_no2                   0.01352273324   0.01352286947
## gamma.bc_st_smk                   0.07851740968   0.07851717733
## alpha.const.(Intercept)           0.06543116740   0.06542869285
## alpha.const.impervious_2500       0.05707264495   0.05707578943
## alpha.const.open_2500             0.02000919623   0.02001229353
## alpha.const.low_int_100           0.00937521426   0.00937743748
## alpha.const.med_int_50            0.00456639825   0.00456603816
## alpha.const.high_int_50           0.01781989915   0.01781991113
## alpha.const.high_int_100         -0.02370474049  -0.02370457334
## alpha.const.ag_250               -0.00334025874  -0.00333995646
## alpha.const.pop_den_50            0.00328540337   0.00328528644
## alpha.const.dist_m_compost        0.00555323095   0.00555324750
## alpha.const.dist_m_military       0.01974191870   0.01974152276
## alpha.const.len_m_highways_2500   0.00099903083   0.00099843249
## alpha.const.aadt_100              0.03716566455   0.03716646214
## alpha.const.aadt_2500            -0.00037352476  -0.00037416735
## alpha.V1.(Intercept)             -0.28060517054  -0.28060374168
## alpha.V1.impervious_2500         -0.05848394601  -0.05848066698
## alpha.V1.open_2500               -0.04262832685  -0.04262569307
## alpha.V1.low_int_100              0.00009773445   0.00009847186
## alpha.V1.med_int_50              -0.00460878522  -0.00460770079
## alpha.V1.high_int_50              0.00945924839   0.00945862328
## alpha.V1.high_int_100            -0.03360667944  -0.03360521276
## alpha.V1.ag_250                  -0.00870057001  -0.00869764735
## alpha.V1.pop_den_50              -0.01322919414  -0.01322921414
## alpha.V1.dist_m_compost          -0.02451066455  -0.02450821803
## alpha.V1.dist_m_military         -0.01284003549  -0.01283804364
## alpha.V1.len_m_highways_2500      0.00676610946   0.00676597296
## alpha.V1.aadt_100                 0.01540981939   0.01541238778
## alpha.V1.aadt_2500                0.00815720131   0.00815813211
## alpha.V2.(Intercept)             -0.12757195065  -0.12757038744
## alpha.V2.impervious_2500         -0.01960994088  -0.01960186676
## alpha.V2.open_2500                0.00892103357   0.00892746081
## alpha.V2.low_int_100              0.00423074629   0.00423400166
## alpha.V2.med_int_50              -0.00497594797  -0.00497482767
## alpha.V2.high_int_50             -0.00820416864  -0.00820405359
## alpha.V2.high_int_100            -0.03637112339  -0.03637068810
## alpha.V2.ag_250                  -0.02647595367  -0.02647294999
## alpha.V2.pop_den_50               0.00306153097   0.00306150133
## alpha.V2.dist_m_compost           0.00613488806   0.00613702136
## alpha.V2.dist_m_military          0.01212160894   0.01212302964
## alpha.V2.len_m_highways_2500      0.01447235020   0.01447087668
## alpha.V2.aadt_100                 0.00086938523   0.00087331688
## alpha.V2.aadt_2500                0.00041704442   0.00041736198
## log.nugget.const.iid            -15.00000000000 -15.00000000000
## log.nugget.V1.iid                -8.67701485586  -8.67372202465
## log.nugget.V2.iid                -7.26445551386  -7.26594352389
## nu.log.nugget.(Intercept).iid    -4.52363858514  -4.52364767069
## 
## Function value(s):
## [1] 1343.189 1343.189 1343.189 1343.189 1343.189

9.2.3 Cross-validation

Define the CV groups (and don’t forget to set the seed here!)

set.seed(123)

unique(colnames(bc_obs2))
##  [1] "d_2"     "d_4"     "d_6"     "d_8"     "d_16"    "d_18"    "d_20"   
##  [8] "d_12"    "d_14"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_15"    "d_17"    "d_19"    "d_11"    "d_13"    "d_21"    "d_23"   
## [22] "d_25"    "d_28"    "d_30"    "d_32"    "d_40"    "d_41"    "d_42"   
## [29] "d_10"    "d_34"    "d_36"    "d_38"    "d_43"    "d_44"    "d_45"   
## [36] "d_3"     "d_1"     "d_27"    "d_29"    "d_31"    "d_39"    "d_9"    
## [43] "d_33"    "d_35"    "d_37"    "d_49"    "d_51"    "d_55"    "d_52"   
## [50] "d_56"    "d_50"    "d_54"    "d_46"    "d_47"    "d_53"    "d_48"   
## [57] "d_58"    "d_59"    "d_60"    "d_57"    "central"
Ind.cv.4.1 <- createCV(denver.model.4.1, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.4.1 <- sapply(split(denver.model.4.1$obs$ID, Ind.cv.4.1), unique)
print(sapply(ID.cv.4.1, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.4.1)
## Ind.cv.4.1
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.4.1 <- apply(sapply(ID.cv.4.1,function(x) denver.model.4.1$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.4.1) <- denver.model.4.1$locations$ID
print(I.col.4.1)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.4.1$locations$long,
     denver.model.4.1$locations$lat,
     pch=23+floor(I.col.4.1/max(I.col.4.1)+.5), bg=I.col.4.1,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.4.1.cv <- coef(est.denver.model.4.1, pars="cov")[,c("par","init")]
x.init.4.1.cv

Run the model with cross validation.

est.denver.4.1.cv <- estimateCV(denver.model.4.1, x.init.4.1.cv, Ind.cv.4.1)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=        -1218  |proj g|=       11.333
## At iterate    10  f =      -1218.3  |proj g|=        1.0687
## At iterate    20  f =      -1218.5  |proj g|=       0.21248
## 
## iterations 28
## function evaluations 35
## segments explored during Cauchy searches 28
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 1.47065e-06
## final function value -1218.51
## 
## F = -1218.51
## final  value -1218.513282 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1118.2  |proj g|=           20
## At iterate    10  f =      -1217.8  |proj g|=       0.45531
## At iterate    20  f =      -1218.5  |proj g|=      0.062744
## 
## iterations 21
## function evaluations 39
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0578013
## final function value -1218.51
## 
## F = -1218.51
## l(0) > u(0).  No feasible solutionfinal  value -1218.506308 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1229.9  |proj g|=       7.2846
## At iterate    10  f =        -1230  |proj g|=       0.24015
## At iterate    20  f =      -1230.2  |proj g|=      0.014525
## 
## iterations 25
## function evaluations 31
## segments explored during Cauchy searches 25
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 8.98854e-06
## final function value -1230.17
## 
## F = -1230.17
## final  value -1230.165111 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1134.1  |proj g|=           20
## At iterate    10  f =      -1229.6  |proj g|=        2.4545
## At iterate    20  f =      -1230.2  |proj g|=       0.61722
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 22
## function evaluations 61
## segments explored during Cauchy searches 26
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00280813
## final function value -1230.16
## 
## F = -1230.16
## l(0) > u(0).  No feasible solutionfinal  value -1230.162557 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=        -1234  |proj g|=       9.2407
## At iterate    10  f =      -1235.1  |proj g|=       0.02955
## At iterate    20  f =      -1235.2  |proj g|=       0.35003
## 
## iterations 28
## function evaluations 39
## segments explored during Cauchy searches 28
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0105392
## final function value -1235.19
## 
## F = -1235.19
## final  value -1235.190152 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1129  |proj g|=           20
## At iterate    10  f =      -1234.9  |proj g|=        0.2568
## At iterate    20  f =      -1235.2  |proj g|=     0.0020147
## 
## iterations 20
## function evaluations 25
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00201465
## final function value -1235.19
## 
## F = -1235.19
## final  value -1235.188468 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1197.9  |proj g|=       14.827
## At iterate    10  f =      -1198.2  |proj g|=       0.13057
## At iterate    20  f =      -1198.2  |proj g|=       0.23754
## 
## iterations 25
## function evaluations 32
## segments explored during Cauchy searches 25
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00403617
## final function value -1198.23
## 
## F = -1198.23
## final  value -1198.229925 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1098.7  |proj g|=           20
## At iterate    10  f =      -1197.6  |proj g|=         1.382
## At iterate    20  f =      -1198.1  |proj g|=       0.49511
## At iterate    30  f =      -1198.2  |proj g|=       0.51951
## 
## iterations 35
## function evaluations 59
## segments explored during Cauchy searches 38
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0169562
## final function value -1198.23
## 
## F = -1198.23
## l(0) > u(0).  No feasible solutionfinal  value -1198.229925 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1215.3  |proj g|=       13.611
## At iterate    10  f =      -1216.6  |proj g|=      0.042331
## At iterate    20  f =      -1216.7  |proj g|=        1.1409
## 
## iterations 24
## function evaluations 30
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000382074
## final function value -1216.67
## 
## F = -1216.67
## final  value -1216.673819 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1110.8  |proj g|=           20
## At iterate    10  f =      -1216.3  |proj g|=        1.3388
## At iterate    20  f =      -1216.7  |proj g|=       0.10261
## 
## iterations 21
## function evaluations 33
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.092021
## final function value -1216.67
## 
## F = -1216.67
## final  value -1216.671533 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1244.4  |proj g|=       9.2692
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1244.582945 
## stopped after 8 iterations
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1144.7  |proj g|=           20
## At iterate    10  f =        -1244  |proj g|=       0.42585
## At iterate    20  f =      -1244.5  |proj g|=      0.019073
## At iterate    30  f =      -1244.6  |proj g|=     0.0010735
## 
## iterations 30
## function evaluations 47
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.00107351
## final function value -1244.58
## 
## F = -1244.58
## final  value -1244.584009 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1237.1  |proj g|=       8.6061
## At iterate    10  f =      -1238.5  |proj g|=       0.46165
## At iterate    20  f =      -1238.6  |proj g|=     0.0083194
## 
## iterations 21
## function evaluations 38
## segments explored during Cauchy searches 21
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00831949
## final function value -1238.57
## 
## F = -1238.57
## l(0) > u(0).  No feasible solutionfinal  value -1238.568585 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1134.4  |proj g|=           20
## At iterate    10  f =      -1237.4  |proj g|=       0.83814
## At iterate    20  f =      -1238.5  |proj g|=      0.073735
## At iterate    30  f =      -1238.6  |proj g|=      0.043272
## 
## iterations 32
## function evaluations 42
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00154997
## final function value -1238.57
## 
## F = -1238.57
## final  value -1238.568579 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=        -1224  |proj g|=       11.834
## At iterate    10  f =      -1224.3  |proj g|=        1.2122
## At iterate    20  f =      -1224.5  |proj g|=       0.08851
## 
## iterations 23
## function evaluations 29
## segments explored during Cauchy searches 23
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0027075
## final function value -1224.53
## 
## F = -1224.53
## final  value -1224.530945 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1123.8  |proj g|=           20
## At iterate    10  f =      -1223.9  |proj g|=        1.7173
## At iterate    20  f =      -1224.5  |proj g|=      0.015229
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 22
## function evaluations 55
## segments explored during Cauchy searches 26
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0399123
## final function value -1224.53
## 
## F = -1224.53
## final  value -1224.527890 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1231.5  |proj g|=       13.953
## 
## iterations 3
## function evaluations 8
## segments explored during Cauchy searches 3
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.125799
## final function value -1231.77
## 
## F = -1231.77
## final  value -1231.766728 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1131.1  |proj g|=           20
## At iterate    10  f =      -1231.1  |proj g|=         2.257
## At iterate    20  f =      -1231.7  |proj g|=      0.050557
## 
## iterations 22
## function evaluations 29
## segments explored during Cauchy searches 25
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 0
## norm of the final projected gradient 0.203878
## final function value -1231.69
## 
## F = -1231.69
## final  value -1231.693861 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 1 variables are exactly at the bounds
## At iterate     0  f=      -1221.2  |proj g|=       10.938
## At iterate    10  f =      -1221.5  |proj g|=       0.13301
## At iterate    20  f =      -1221.5  |proj g|=        2.2315
## 
## iterations 29
## function evaluations 48
## segments explored during Cauchy searches 29
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0143461
## final function value -1221.66
## 
## F = -1221.66
## l(0) > u(0).  No feasible solutionfinal  value -1221.658567 
## converged
## 
## Optimisation using starting value 2/2
## N = 4, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1123.5  |proj g|=           20
## At iterate    10  f =      -1220.9  |proj g|=        1.1985
## At iterate    20  f =      -1221.4  |proj g|=       0.11978
## ys=-8.666e-03  -gs= 5.193e-02, BFGS update SKIPPED
## At iterate    30  f =      -1221.6  |proj g|=       0.64215
## 
## iterations 37
## function evaluations 66
## segments explored during Cauchy searches 40
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0190339
## final function value -1221.66
## 
## F = -1221.66
## l(0) > u(0).  No feasible solutionfinal  value -1221.657095 
## converged
## 
print(est.denver.4.1.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 10 converged, 0 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence conv   eigen.min eigen.all.min
## 1  1218.506        TRUE TRUE 0.002875010            NA
## 2  1230.163        TRUE TRUE 0.002855382            NA
## 3  1235.190        TRUE TRUE 0.001129657            NA
## 4  1198.230        TRUE TRUE 0.002664523            NA
## 5  1216.672        TRUE TRUE 0.002483887            NA
## 6  1244.584        TRUE TRUE 0.002754300            NA
## 7  1238.569        TRUE TRUE 0.001064929            NA
## 8  1224.528        TRUE TRUE 0.003145641            NA
## 9  1231.767        TRUE TRUE 0.002750414            NA
## 10 1221.659        TRUE TRUE 0.001685636            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.4.1, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.4.1.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data4.2, denver.model.4.1, est.denver.model.4.1, est.denver.4.1.cv,
     file = here::here("Results", "Denver_ST_Model_4.1.rdata"))

9.2.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.4.1.cv <- predictCV(denver.model.4.1, est.denver.4.1.cv, LTA = T)
pred.4.1.cv.log <- predictCV(denver.model.4.1, est.denver.4.1.cv,
                             LTA = T, transform="unbiased")

names(pred.4.1.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.4.1.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.10175318 0.10175318 0.10175318
## average 0.05724144 0.05724144 0.05724144
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.7561881  0.7561881 0.7561881
## average 0.8564912  0.8564912 0.8564912
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9675851
## average 0.8166667
summary(pred.4.1.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX   EX.pred
## obs     0.12021324 0.12021324 0.12022720 0.1207429
## average 0.06183566 0.06183566 0.06185318 0.0626662
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.7762318  0.7762318 0.7761798 0.7742555
## average 0.8971191  0.8971191 0.8970608 0.8943368
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9675851
## average 0.8333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.1.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.1.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod4.1.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.1.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.1.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

9.3 Model 4.2: Smoothing in the error term

9.3.1 Create the model object

For this version of the model, use iid for cov.beta (beta, beta1, beta2) and exp for cov.nu (error). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data4.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR4.2 <- list(covar_fun, covar_fun, covar_fun)

cov.beta4.2 <-  list(covf = c("iid", "iid", "iid"), nugget = T)
cov.nu4.2 <- list(covf = "exp", nugget = T, random.effect = FALSE)
locations4.2 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.4.2 <- createSTmodel(denver.data4.2, LUR = LUR4.2,
                                  ST = c("bc_st_no2", "bc_st_smk"),
                                  cov.beta = cov.beta4.2, cov.nu = cov.nu4.2,
                                  locations = locations4.2)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.4.2
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, iid, iid 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

9.3.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.4.2, all=FALSE)
names
## [1] "log.nugget.const.iid"          "log.nugget.V1.iid"            
## [3] "log.nugget.V2.iid"             "nu.log.range.exp"             
## [5] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# x.init.4.2 <- cbind(c(0, 0, 0, 0, 0, 0),
#                     c(-1, -1, -1, 0, -1, -1),
#                     c(-1, -1, -1, 0, -5, -1),
#                     c(-5, -5, -5, 0, -1, -5),
#                     c(-5, -5, -5, 0, -5, -5),
#                     c(-1, -1, -1, 2, -1, -1),
#                     c(-1, -1, -1, 2, -5, -1),
#                     c(-5, -5, -5, 2, -1, -5),
#                     c(-5, -5, -5, 2, -5, -5),
#                     c(-1, -1, -1, 4, -1, -1),
#                     c(-1, -1, -1, 4, -5, -1),
#                     c(-5, -5, -5, 4, -1, -5),
#                     c(-5, -5, -5, 4, -5, -5))

x.init.4.2 <- cbind(c(0, 0, 0, 0, 0, 0),
                    c(-10, -5, -5, 4, -3, -5),
                    c(-10, -5, -5, 4, -5, -5),
                    c(-10, -5, -5, 6, -3, -5),
                    c(-10, -5, -5, 6, -5, -5),
                    c(-10, -5, -5, 8, -3, -5),
                    c(-10, -5, -5, 8, -5, -5),
                    c(-10, -5, -5, 10, -3, -5),
                    c(-10, -5, -5, 10, -5, -5))

rownames(x.init.4.2) <- loglikeSTnames(denver.model.4.2, all=FALSE)
x.init.4.2
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## log.nugget.const.iid             0  -10  -10  -10  -10  -10  -10  -10  -10
## log.nugget.V1.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## log.nugget.V2.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## nu.log.range.exp                 0    4    4    6    6    8    8   10   10
## nu.log.sill.exp                  0   -3   -5   -3   -5   -3   -5   -3   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5   -5   -5   -5   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.4.2 <- estimate.STmodel(denver.model.4.2, x.init.4.2)
## Optimisation using starting value 1/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       373.04  |proj g|=           15
## At iterate    10  f =      -1342.3  |proj g|=        0.5144
## At iterate    20  f =      -1343.2  |proj g|=       0.09129
## 
## iterations 21
## function evaluations 42
## segments explored during Cauchy searches 24
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 0
## norm of the final projected gradient 0.0912903
## final function value -1343.19
## 
## F = -1343.19
## l(0) > u(0).  No feasible solutionfinal  value -1343.187126 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -998.22  |proj g|=           12
## At iterate    10  f =      -1342.4  |proj g|=        1.3389
## At iterate    20  f =      -1343.1  |proj g|=        1.1152
## At iterate    30  f =      -1343.2  |proj g|=       0.41813
## 
## iterations 39
## function evaluations 60
## segments explored during Cauchy searches 42
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 0
## norm of the final projected gradient 0.151544
## final function value -1343.17
## 
## F = -1343.17
## final  value -1343.172068 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1296.4  |proj g|=           10
## At iterate    10  f =      -1342.5  |proj g|=        1.9346
## At iterate    20  f =      -1343.1  |proj g|=        3.8488
## At iterate    30  f =      -1343.2  |proj g|=       0.35525
## At iterate    40  f =      -1343.2  |proj g|=       0.29009
## 
## iterations 41
## function evaluations 63
## segments explored during Cauchy searches 44
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.290088
## final function value -1343.19
## 
## F = -1343.19
## final  value -1343.190852 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1000.5  |proj g|=           12
## At iterate    10  f =      -1471.5  |proj g|=        11.166
## At iterate    20  f =        -1529  |proj g|=       0.85111
## At iterate    30  f =      -1529.9  |proj g|=        1.1752
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1529.938613 
## stopped after 37 iterations
## Optimisation using starting value 5/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1298  |proj g|=           10
## At iterate    10  f =      -1464.7  |proj g|=        11.912
## At iterate    20  f =      -1510.6  |proj g|=        8.1766
## At iterate    30  f =      -1516.4  |proj g|=        4.7829
## 
## iterations 35
## function evaluations 58
## segments explored during Cauchy searches 38
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0114214
## final function value -1516.83
## 
## F = -1516.83
## final  value -1516.826840 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1044.5  |proj g|=           12
## At iterate    10  f =      -1529.5  |proj g|=       0.67302
## At iterate    20  f =      -1529.9  |proj g|=       0.18302
## 
## iterations 27
## function evaluations 32
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00028477
## final function value -1529.94
## 
## F = -1529.94
## final  value -1529.938604 
## converged
## Optimisation using starting value 7/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1322.1  |proj g|=           10
## At iterate    10  f =      -1528.6  |proj g|=        2.5616
## At iterate    20  f =      -1529.7  |proj g|=        2.6653
## At iterate    30  f =      -1529.9  |proj g|=     0.0077849
## 
## iterations 32
## function evaluations 38
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.010262
## final function value -1529.94
## 
## F = -1529.94
## final  value -1529.938606 
## converged
## Optimisation using starting value 8/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1226.5  |proj g|=           12
## At iterate    10  f =      -1529.2  |proj g|=         2.197
## At iterate    20  f =      -1529.6  |proj g|=         1.587
## At iterate    30  f =      -1529.9  |proj g|=        0.1921
## 
## iterations 39
## function evaluations 52
## segments explored during Cauchy searches 43
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0350508
## final function value -1529.94
## 
## F = -1529.94
## l(0) > u(0).  No feasible solutionfinal  value -1529.938613 
## converged
## Optimisation using starting value 9/9
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1392.6  |proj g|=           10
## At iterate    10  f =      -1529.3  |proj g|=        5.8372
## At iterate    20  f =      -1529.9  |proj g|=       0.45951
## At iterate    30  f =      -1529.9  |proj g|=      0.016046
## 
## iterations 31
## function evaluations 58
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0160463
## final function value -1529.94
## 
## F = -1529.94
## l(0) > u(0).  No feasible solutionfinal  value -1529.938606 
## converged
print(est.denver.model.4.2)
## Optimisation for STmodel with 9 starting points.
##   Results: 4 converged, 5 not converged, 0 failed.
##   Best result for starting point 4, optimisation has NOT converged
##   Best converged result for starting point 8 
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                             [,1]            [,2]
## gamma.bc_st_no2                   0.013484729122   0.01346965148
## gamma.bc_st_smk                   0.078451695699   0.07844177353
## alpha.const.(Intercept)           0.066241950025   0.06655435382
## alpha.const.impervious_2500       0.056770149818   0.05658987328
## alpha.const.open_2500             0.019709975665   0.01953216151
## alpha.const.low_int_100           0.009171710998   0.00905119867
## alpha.const.med_int_50            0.004637202693   0.00466838055
## alpha.const.high_int_50           0.017853111533   0.01786066050
## alpha.const.high_int_100         -0.023769542366  -0.02378901395
## alpha.const.ag_250               -0.003361478715  -0.00337582235
## alpha.const.pop_den_50            0.003265088452   0.00326142667
## alpha.const.dist_m_compost        0.005550932539   0.00555122060
## alpha.const.dist_m_military       0.019750205717   0.01976075238
## alpha.const.len_m_highways_2500   0.001071719403   0.00110746474
## alpha.const.aadt_100              0.037149032075   0.03712112228
## alpha.const.aadt_2500            -0.000329639765  -0.00029756144
## alpha.V1.(Intercept)             -0.280837685426  -0.28093919210
## alpha.V1.impervious_2500         -0.058655342999  -0.05875126997
## alpha.V1.open_2500               -0.042810992704  -0.04291840603
## alpha.V1.low_int_100              0.000008294724  -0.00003520904
## alpha.V1.med_int_50              -0.004690751729  -0.00473330715
## alpha.V1.high_int_50              0.009554040397   0.00961135683
## alpha.V1.high_int_100            -0.033891928967  -0.03404700714
## alpha.V1.ag_250                  -0.008991272785  -0.00916759985
## alpha.V1.pop_den_50              -0.013211103245  -0.01321877377
## alpha.V1.dist_m_compost          -0.024740783484  -0.02488075871
## alpha.V1.dist_m_military         -0.013000745311  -0.01310256893
## alpha.V1.len_m_highways_2500      0.006741480775   0.00671736761
## alpha.V1.aadt_100                 0.015173351498   0.01506988892
## alpha.V1.aadt_2500                0.008064890324   0.00801121320
## alpha.V2.(Intercept)             -0.127638579479  -0.12767927097
## alpha.V2.impervious_2500         -0.020039306596  -0.02032008549
## alpha.V2.open_2500                0.008493521826   0.00822192016
## alpha.V2.low_int_100              0.003884981063   0.00369871042
## alpha.V2.med_int_50              -0.004931844218  -0.00492892825
## alpha.V2.high_int_50             -0.007923220473  -0.00781341608
## alpha.V2.high_int_100            -0.037059195621  -0.03733383524
## alpha.V2.ag_250                  -0.026765515341  -0.02694559073
## alpha.V2.pop_den_50               0.003051259687   0.00304161919
## alpha.V2.dist_m_compost           0.005880353461   0.00574017816
## alpha.V2.dist_m_military          0.011956625218   0.01186400173
## alpha.V2.len_m_highways_2500      0.014548471654   0.01457579813
## alpha.V2.aadt_100                 0.000873339356   0.00081786713
## alpha.V2.aadt_2500                0.000370940749   0.00035631464
## log.nugget.const.iid            -14.156556445717 -13.67257324537
## log.nugget.V1.iid                -8.994201170321  -9.22625935466
## log.nugget.V2.iid                -7.165020256905  -7.11814749697
## nu.log.range.exp                  0.000000000000   4.08965713216
## nu.log.sill.exp                  -7.606738808625  -7.36174788566
## nu.log.nugget.(Intercept).exp    -4.569444900346  -4.58203385448
##                                            [,3]           [,4]           [,5]
## gamma.bc_st_no2                   0.01347954353   0.0185404893   0.0178804601
## gamma.bc_st_smk                   0.07844447438   0.0536771629   0.0556930910
## alpha.const.(Intercept)           0.06636184524  -0.0101968459  -0.0001459460
## alpha.const.impervious_2500       0.05674182984   0.0647219471   0.0466989768
## alpha.const.open_2500             0.01968414572   0.0289415437   0.0092724435
## alpha.const.low_int_100           0.00915822455   0.0207113556   0.0098564643
## alpha.const.med_int_50            0.00465263829  -0.0053597005  -0.0081649275
## alpha.const.high_int_50           0.01785981471   0.0057730930   0.0023564765
## alpha.const.high_int_100         -0.02377972942  -0.0003455523   0.0015108772
## alpha.const.ag_250               -0.00336782217  -0.0014557452  -0.0018730502
## alpha.const.pop_den_50            0.00325992423   0.0023775276   0.0010893074
## alpha.const.dist_m_compost        0.00554635915   0.0003440036   0.0005672099
## alpha.const.dist_m_military       0.01973621438   0.0064458656   0.0106550005
## alpha.const.len_m_highways_2500   0.00107167291   0.0053511171   0.0123680477
## alpha.const.aadt_100              0.03715586549   0.0221989001   0.0163374968
## alpha.const.aadt_2500            -0.00032771320  -0.0102482952  -0.0062700195
## alpha.V1.(Intercept)             -0.28086555285  -0.2934905021  -0.2987921069
## alpha.V1.impervious_2500         -0.05865049881  -0.0570650489  -0.0472434315
## alpha.V1.open_2500               -0.04284990987  -0.0384543500  -0.0315186688
## alpha.V1.low_int_100             -0.00000354034  -0.0079337752  -0.0053073743
## alpha.V1.med_int_50              -0.00470298852  -0.0045649086  -0.0008540469
## alpha.V1.high_int_50              0.00958379064  -0.0005734890   0.0046008522
## alpha.V1.high_int_100            -0.03396425266  -0.0131323916  -0.0239306852
## alpha.V1.ag_250                  -0.00906660493   0.0123435400   0.0052709617
## alpha.V1.pop_den_50              -0.01323629851  -0.0023724473  -0.0046382807
## alpha.V1.dist_m_compost          -0.02479937603  -0.0042872931  -0.0074605362
## alpha.V1.dist_m_military         -0.01303668697   0.0078911673   0.0055121454
## alpha.V1.len_m_highways_2500      0.00670623854   0.0124493443   0.0059407021
## alpha.V1.aadt_100                 0.01518192556   0.0174096235   0.0192655645
## alpha.V1.aadt_2500                0.00804877876   0.0139784321   0.0112099662
## alpha.V2.(Intercept)             -0.12761651386  -0.1073094658  -0.1117638904
## alpha.V2.impervious_2500         -0.02002349522  -0.0066331873  -0.0117298050
## alpha.V2.open_2500                0.00845674743   0.0187404830   0.0091309552
## alpha.V2.low_int_100              0.00385652602   0.0041272608  -0.0034351574
## alpha.V2.med_int_50              -0.00491325480  -0.0155016517  -0.0135900553
## alpha.V2.high_int_50             -0.00783925431  -0.0334610184  -0.0305952962
## alpha.V2.high_int_100            -0.03722854138   0.0163554786   0.0066930939
## alpha.V2.ag_250                  -0.02684674153  -0.0042938225  -0.0118499217
## alpha.V2.pop_den_50               0.00303382970   0.0086724131   0.0058320753
## alpha.V2.dist_m_compost           0.00581077782   0.0275748009   0.0244333309
## alpha.V2.dist_m_military          0.01190144855   0.0272817019   0.0275365158
## alpha.V2.len_m_highways_2500      0.01450204615   0.0250630745   0.0236835137
## alpha.V2.aadt_100                 0.00094050875  -0.0207323534  -0.0241462540
## alpha.V2.aadt_2500                0.00036949453  -0.0021438666  -0.0015398548
## log.nugget.const.iid            -15.00000000000 -15.0000000000  -7.1244062610
## log.nugget.V1.iid                -9.00753089598  -6.6232283131 -14.2517674828
## log.nugget.V2.iid                -7.17846292590  -6.0793490394  -6.6206001612
## nu.log.range.exp                  4.09962327885  15.0000000000  15.0000000000
## nu.log.sill.exp                  -7.52430240343  -3.8089218835  -3.8213379875
## nu.log.nugget.(Intercept).exp    -4.57264333232  -5.6747978582  -5.5618460572
##                                           [,6]           [,7]           [,8]
## gamma.bc_st_no2                   0.0185393129   0.0185398453   0.0185408885
## gamma.bc_st_smk                   0.0536796058   0.0536787647   0.0536766126
## alpha.const.(Intercept)          -0.0101687820  -0.0101810981  -0.0102065029
## alpha.const.impervious_2500       0.0647223303   0.0647220746   0.0647208746
## alpha.const.open_2500             0.0289417005   0.0289416418   0.0289404197
## alpha.const.low_int_100           0.0207116715   0.0207120811   0.0207103444
## alpha.const.med_int_50           -0.0053601463  -0.0053607481  -0.0053592220
## alpha.const.high_int_50           0.0057728803   0.0057733087   0.0057730839
## alpha.const.high_int_100         -0.0003449158  -0.0003449720  -0.0003460503
## alpha.const.ag_250               -0.0014558800  -0.0014556789  -0.0014561651
## alpha.const.pop_den_50            0.0023768965   0.0023773954   0.0023775595
## alpha.const.dist_m_compost        0.0003439690   0.0003437849   0.0003437784
## alpha.const.dist_m_military       0.0064457986   0.0064454052   0.0064461335
## alpha.const.len_m_highways_2500   0.0053514045   0.0053510722   0.0053512639
## alpha.const.aadt_100              0.0221991024   0.0221991214   0.0221984240
## alpha.const.aadt_2500            -0.0102483935  -0.0102481101  -0.0102480742
## alpha.V1.(Intercept)             -0.2934966191  -0.2934912457  -0.2934895508
## alpha.V1.impervious_2500         -0.0570662169  -0.0570686478  -0.0570654755
## alpha.V1.open_2500               -0.0384553127  -0.0384558661  -0.0384563596
## alpha.V1.low_int_100             -0.0079338190  -0.0079327575  -0.0079346629
## alpha.V1.med_int_50              -0.0045652088  -0.0045666185  -0.0045643809
## alpha.V1.high_int_50             -0.0005733535  -0.0005749361  -0.0005718452
## alpha.V1.high_int_100            -0.0131317560  -0.0131269558  -0.0131365496
## alpha.V1.ag_250                   0.0123428992   0.0123446601   0.0123404896
## alpha.V1.pop_den_50              -0.0023727388  -0.0023718499  -0.0023738594
## alpha.V1.dist_m_compost          -0.0042876161  -0.0042877417  -0.0042895075
## alpha.V1.dist_m_military          0.0078907580   0.0078898596   0.0078903928
## alpha.V1.len_m_highways_2500      0.0124495596   0.0124506528   0.0124482012
## alpha.V1.aadt_100                 0.0174094524   0.0174092016   0.0174090628
## alpha.V1.aadt_2500                0.0139783991   0.0139780921   0.0139783539
## alpha.V2.(Intercept)             -0.1073052650  -0.1073031688  -0.1073122505
## alpha.V2.impervious_2500         -0.0066346390  -0.0066370570  -0.0066339992
## alpha.V2.open_2500                0.0187393235   0.0187383824   0.0187379942
## alpha.V2.low_int_100              0.0041274393   0.0041287178   0.0041253469
## alpha.V2.med_int_50              -0.0155021480  -0.0155039228  -0.0155005128
## alpha.V2.high_int_50             -0.0334605519  -0.0334618649  -0.0334594704
## alpha.V2.high_int_100             0.0163556475   0.0163601444   0.0163512542
## alpha.V2.ag_250                  -0.0042942442  -0.0042923367  -0.0042973169
## alpha.V2.pop_den_50               0.0086719162   0.0086722232   0.0086710656
## alpha.V2.dist_m_compost           0.0275738857   0.0275738003   0.0275726354
## alpha.V2.dist_m_military          0.0272813098   0.0272806873   0.0272809662
## alpha.V2.len_m_highways_2500      0.0250635069   0.0250646646   0.0250619614
## alpha.V2.aadt_100                -0.0207330008  -0.0207332122  -0.0207329814
## alpha.V2.aadt_2500               -0.0021436602  -0.0021432865  -0.0021439819
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid                -6.6233483334  -6.6229389813  -6.6237418872
## log.nugget.V2.iid                -6.0791592289  -6.0784993315  -6.0793938424
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8088302771  -3.8088640719  -3.8090330308
## nu.log.nugget.(Intercept).exp    -5.6749197762  -5.6749192068  -5.6747330444
##                                           [,9]
## gamma.bc_st_no2                   0.0185393235
## gamma.bc_st_smk                   0.0536801280
## alpha.const.(Intercept)          -0.0101690078
## alpha.const.impervious_2500       0.0647209470
## alpha.const.open_2500             0.0289401912
## alpha.const.low_int_100           0.0207107028
## alpha.const.med_int_50           -0.0053601349
## alpha.const.high_int_50           0.0057729556
## alpha.const.high_int_100         -0.0003451892
## alpha.const.ag_250               -0.0014564585
## alpha.const.pop_den_50            0.0023767654
## alpha.const.dist_m_compost        0.0003435206
## alpha.const.dist_m_military       0.0064459057
## alpha.const.len_m_highways_2500   0.0053516328
## alpha.const.aadt_100              0.0221985867
## alpha.const.aadt_2500            -0.0102479916
## alpha.V1.(Intercept)             -0.2934966780
## alpha.V1.impervious_2500         -0.0570690489
## alpha.V1.open_2500               -0.0384591703
## alpha.V1.low_int_100             -0.0079345053
## alpha.V1.med_int_50              -0.0045654796
## alpha.V1.high_int_50             -0.0005718260
## alpha.V1.high_int_100            -0.0131344560
## alpha.V1.ag_250                   0.0123391153
## alpha.V1.pop_den_50              -0.0023744447
## alpha.V1.dist_m_compost          -0.0042910553
## alpha.V1.dist_m_military          0.0078888552
## alpha.V1.len_m_highways_2500      0.0124487189
## alpha.V1.aadt_100                 0.0174083920
## alpha.V1.aadt_2500                0.0139780903
## alpha.V2.(Intercept)             -0.1073049600
## alpha.V2.impervious_2500         -0.0066382146
## alpha.V2.open_2500                0.0187344252
## alpha.V2.low_int_100              0.0041255855
## alpha.V2.med_int_50              -0.0155019031
## alpha.V2.high_int_50             -0.0334587660
## alpha.V2.high_int_100             0.0163523418
## alpha.V2.ag_250                  -0.0042984138
## alpha.V2.pop_den_50               0.0086698217
## alpha.V2.dist_m_compost           0.0275701073
## alpha.V2.dist_m_military          0.0272796312
## alpha.V2.len_m_highways_2500      0.0250629034
## alpha.V2.aadt_100                -0.0207344810
## alpha.V2.aadt_2500               -0.0021434611
## log.nugget.const.iid            -15.0000000000
## log.nugget.V1.iid                -6.6238649298
## log.nugget.V2.iid                -6.0786446291
## nu.log.range.exp                 15.0000000000
## nu.log.sill.exp                  -3.8088747096
## nu.log.nugget.(Intercept).exp    -5.6748511233
## 
## Function value(s):
## [1] 1343.187 1343.172 1343.191 1529.939 1516.827 1529.939 1529.939 1529.939
## [9] 1529.939

9.3.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs2))
##  [1] "d_2"     "d_4"     "d_6"     "d_8"     "d_16"    "d_18"    "d_20"   
##  [8] "d_12"    "d_14"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_15"    "d_17"    "d_19"    "d_11"    "d_13"    "d_21"    "d_23"   
## [22] "d_25"    "d_28"    "d_30"    "d_32"    "d_40"    "d_41"    "d_42"   
## [29] "d_10"    "d_34"    "d_36"    "d_38"    "d_43"    "d_44"    "d_45"   
## [36] "d_3"     "d_1"     "d_27"    "d_29"    "d_31"    "d_39"    "d_9"    
## [43] "d_33"    "d_35"    "d_37"    "d_49"    "d_51"    "d_55"    "d_52"   
## [50] "d_56"    "d_50"    "d_54"    "d_46"    "d_47"    "d_53"    "d_48"   
## [57] "d_58"    "d_59"    "d_60"    "d_57"    "central"
Ind.cv.4.2 <- createCV(denver.model.4.2, groups = 10, #min.dist = .1,
                           subset = paste0("d_", c(1:60)))

ID.cv.4.2 <- sapply(split(denver.model.4.2$obs$ID, Ind.cv.4.2), unique)
print(sapply(ID.cv.4.2, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.4.2)
## Ind.cv.4.2
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.4.2 <- apply(sapply(ID.cv.4.2, function(x) denver.model.4.2$locations$ID%in% x), 1,
                       function(x) if(sum(x)==1) which(x) else 0)
names(I.col.4.2) <- denver.model.4.2$locations$ID
print(I.col.4.2)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.4.2$locations$long,
     denver.model.4.2$locations$lat,
     pch=23+floor(I.col.4.2/max(I.col.4.2)+.5), bg=I.col.4.2,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.4.2.cv <- coef(est.denver.model.4.2, pars="cov")[,c("par","init")]
x.init.4.2.cv

Run the model with cross validation

est.denver.4.2.cv <- estimateCV(denver.model.4.2, x.init.4.2.cv, Ind.cv.4.2)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1391.8  |proj g|=       2.0506
## 
## iterations 8
## function evaluations 16
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00657006
## final function value -1392.48
## 
## F = -1392.48
## final  value -1392.480113 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1112.9  |proj g|=           12
## At iterate    10  f =      -1391.9  |proj g|=        1.2365
## At iterate    20  f =      -1392.3  |proj g|=        1.2012
## At iterate    30  f =      -1392.5  |proj g|=      0.024644
## 
## iterations 32
## function evaluations 38
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0010435
## final function value -1392.48
## 
## F = -1392.48
## final  value -1392.480109 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1398.3  |proj g|=       2.5166
## At iterate    10  f =      -1398.3  |proj g|=     0.0017513
## 
## iterations 10
## function evaluations 12
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00175128
## final function value -1398.35
## 
## F = -1398.35
## final  value -1398.346105 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1119.9  |proj g|=           12
## At iterate    10  f =      -1397.3  |proj g|=        2.2947
## At iterate    20  f =      -1398.1  |proj g|=        2.1287
## At iterate    30  f =      -1398.3  |proj g|=      0.043378
## 
## iterations 32
## function evaluations 38
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0410953
## final function value -1398.35
## 
## F = -1398.35
## final  value -1398.346074 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1402.5  |proj g|=       2.5052
## 
## iterations 9
## function evaluations 20
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0342462
## final function value -1403.08
## 
## F = -1403.08
## final  value -1403.080345 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1121.8  |proj g|=           12
## At iterate    10  f =      -1402.3  |proj g|=         1.481
## At iterate    20  f =      -1402.8  |proj g|=        1.2324
## At iterate    30  f =      -1403.1  |proj g|=      0.037404
## 
## iterations 32
## function evaluations 48
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0298227
## final function value -1403.08
## 
## F = -1403.08
## l(0) > u(0).  No feasible solutionfinal  value -1403.080317 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1365.6  |proj g|=       1.5331
## At iterate    10  f =      -1365.7  |proj g|=      0.080126
## 
## iterations 12
## function evaluations 18
## segments explored during Cauchy searches 12
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0418366
## final function value -1365.69
## 
## F = -1365.69
## final  value -1365.685431 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1089.9  |proj g|=           12
## At iterate    10  f =      -1364.8  |proj g|=         3.395
## At iterate    20  f =      -1365.6  |proj g|=        3.8366
## At iterate    30  f =      -1365.7  |proj g|=       0.48409
## 
## iterations 36
## function evaluations 42
## segments explored during Cauchy searches 40
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0507804
## final function value -1365.69
## 
## F = -1365.69
## final  value -1365.685432 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1378.7  |proj g|=       7.7537
## At iterate    10  f =      -1379.3  |proj g|=      0.051791
## 
## iterations 12
## function evaluations 22
## segments explored during Cauchy searches 12
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0260579
## final function value -1379.29
## 
## F = -1379.29
## final  value -1379.285711 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1108.5  |proj g|=           12
## At iterate    10  f =      -1378.6  |proj g|=        1.1888
## At iterate    20  f =      -1379.2  |proj g|=        1.1165
## At iterate    30  f =      -1379.3  |proj g|=     0.0026987
## 
## iterations 30
## function evaluations 36
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00269871
## final function value -1379.29
## 
## F = -1379.29
## final  value -1379.285697 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1413.3  |proj g|=       5.5872
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## At iterate    10  f =      -1413.4  |proj g|=     0.0017434
## 
## iterations 10
## function evaluations 45
## segments explored during Cauchy searches 11
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00174339
## final function value -1413.43
## 
## F = -1413.43
## l(0) > u(0).  No feasible solutionfinal  value -1413.426665 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1137.8  |proj g|=           12
## At iterate    10  f =      -1412.5  |proj g|=        1.8368
## At iterate    20  f =      -1413.3  |proj g|=        1.1791
## 
## iterations 29
## function evaluations 33
## segments explored during Cauchy searches 33
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00902928
## final function value -1413.43
## 
## F = -1413.43
## final  value -1413.426658 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1404.6  |proj g|=        4.389
## At iterate    10  f =      -1405.1  |proj g|=     0.0053723
## 
## iterations 12
## function evaluations 24
## segments explored during Cauchy searches 12
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00533854
## final function value -1405.13
## 
## F = -1405.13
## l(0) > u(0).  No feasible solutionfinal  value -1405.126711 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1130.3  |proj g|=           12
## At iterate    10  f =      -1403.8  |proj g|=        5.7644
## At iterate    20  f =      -1405.1  |proj g|=       0.82323
## 
## iterations 27
## function evaluations 31
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0303722
## final function value -1405.13
## 
## F = -1405.13
## final  value -1405.126710 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1399.7  |proj g|=       3.1425
## At iterate    10  f =      -1399.8  |proj g|=    0.00065075
## 
## iterations 10
## function evaluations 14
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000650747
## final function value -1399.76
## 
## F = -1399.76
## final  value -1399.760325 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1116.4  |proj g|=           12
## At iterate    10  f =      -1399.2  |proj g|=        1.1723
## At iterate    20  f =      -1399.6  |proj g|=       0.87836
## At iterate    30  f =      -1399.8  |proj g|=      0.015251
## 
## iterations 33
## function evaluations 49
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00176459
## final function value -1399.76
## 
## F = -1399.76
## l(0) > u(0).  No feasible solutionfinal  value -1399.760326 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1402.7  |proj g|=       4.4083
## At iterate    10  f =      -1402.7  |proj g|=      0.020176
## 
## iterations 10
## function evaluations 23
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0201757
## final function value -1402.71
## 
## F = -1402.71
## l(0) > u(0).  No feasible solutionfinal  value -1402.709461 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1120  |proj g|=           12
## At iterate    10  f =      -1401.7  |proj g|=        2.2985
## At iterate    20  f =      -1402.7  |proj g|=       0.26032
## 
## iterations 27
## function evaluations 35
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00574565
## final function value -1402.71
## 
## F = -1402.71
## final  value -1402.709448 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=        -1390  |proj g|=       1.0362
## 
## iterations 8
## function evaluations 22
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0399659
## final function value -1390.05
## 
## F = -1390.05
## l(0) > u(0).  No feasible solutionfinal  value -1390.050332 
## converged
## 
## Optimisation using starting value 2/2
## N = 6, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1110.2  |proj g|=           12
## At iterate    10  f =      -1389.1  |proj g|=        2.0075
## At iterate    20  f =      -1389.8  |proj g|=        1.9117
## At iterate    30  f =      -1390.1  |proj g|=      0.030047
## 
## iterations 33
## function evaluations 40
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00514497
## final function value -1390.05
## 
## F = -1390.05
## final  value -1390.050317 
## converged
## 
print(est.denver.4.2.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 10 converged, 0 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence conv   eigen.min eigen.all.min
## 1  1392.480        TRUE TRUE 0.003388169            NA
## 2  1398.346        TRUE TRUE 0.004076601            NA
## 3  1403.080        TRUE TRUE 0.003870250            NA
## 4  1365.685        TRUE TRUE 0.003721848            NA
## 5  1379.286        TRUE TRUE 0.004587823            NA
## 6  1413.427        TRUE TRUE 0.004910311            NA
## 7  1405.127        TRUE TRUE 0.003579077            NA
## 8  1399.760        TRUE TRUE 0.003290456            NA
## 9  1402.709        TRUE TRUE 0.004123995            NA
## 10 1390.050        TRUE TRUE 0.003957456            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.4.2, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
             col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.4.2.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data4.2, denver.model.4.2, est.denver.model.4.2, est.denver.4.2.cv,
     file = here::here("Results", "Denver_ST_Model_4.2.rdata"))

9.3.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.4.2.cv <- predictCV(denver.model.4.2, est.denver.4.2.cv, LTA = T)
pred.4.2.cv.log <- predictCV(denver.model.4.2, est.denver.4.2.cv,
                             LTA = T, transform="unbiased")

names(pred.4.2.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.4.2.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.11380502 0.11380502 0.09276457
## average 0.07164742 0.07164742 0.06266573
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6950127  0.6950127 0.7973609
## average 0.7751678  0.7751678 0.8280043
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9205835
## average 0.9166667
summary(pred.4.2.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX   EX.pred
## obs     0.13731488 0.13731488 0.10713033 0.1072921
## average 0.08264998 0.08264998 0.07008037 0.0704400
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.7080362  0.7080362 0.8222872 0.8217502
## average 0.8162013  0.8162013 0.8678553 0.8664956
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9205835
## average 0.9333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.2.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.2.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod4.2.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.2.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.2.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

9.4 Model 4.3: Smoothing in beta0 and the error term

9.4.1 Create the model object

For this version of the model, use iid for cov.beta (beta1, beta2) and exp for cov.beta (beta0) and cov.nu (error). Here we can specify different LUR formluae. The length of the LUR list should be number of basis functions + 1.

names(denver.data4.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR4.3 <- list(covar_fun, covar_fun, covar_fun)

cov.beta4.3 <-  list(covf = c("exp", "iid", "iid"), nugget = c(T, T, T))
cov.nu4.3 <- list(covf = "exp", nugget = T, random.effect = FALSE)
locations4.3 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.4.3 <- createSTmodel(denver.data4.2, LUR = LUR4.3,
                                  ST = c("bc_st_no2", "bc_st_smk"),
                                  cov.beta = cov.beta4.3, cov.nu = cov.nu4.3,
                                  locations = locations4.3)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.4.3
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): exp, iid, iid 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

9.4.2 Estimate model parameters

Josh gave some guidance on how to set up the initial values (NOTE: the iid model doesn’t have range or sill values, but the exp model does):

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.4.3, all=FALSE)
names
## [1] "log.range.const.exp"           "log.sill.const.exp"           
## [3] "log.nugget.const.exp"          "log.nugget.V1.iid"            
## [5] "log.nugget.V2.iid"             "nu.log.range.exp"             
## [7] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# x.init.4.3 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0),
#                     c(0, -1, -1, -1, -1, 0, -1, -1),
#                     c(0, -1, -5, -5, -5, 0, -1, -1),
#                     c(0, -5, -1, -1, -1, 0, -5, -5),
#                     c(0, -5, -5, -5, -5, 0, -5, -5),
#                     c(2, -1, -1, -1, -1, 2, -1, -1),
#                     c(2, -1, -5, -5, -5, 2, -1, -1),
#                     c(2, -5, -1, -1, -1, 2, -5, -5),
#                     c(2, -5, -5, -5, -5, 2, -5, -5),
#                     c(4, -1, -1, -1, -1, 4, -1, -1),
#                     c(4, -1, -5, -5, -5, 4, -1, -1),
#                     c(4, -5, -1, -1, -1, 4, -5, -5),
#                     c(4, -5, -5, -5, -5, 4, -5, -5),
#                     c(6, -1, -1, -1, -1, 6, -1, -1),
#                     c(6, -1, -5, -5, -5, 6, -1, -1),
#                     c(6, -5, -1, -1, -1, 6, -5, -5),
#                     c(6, -5, -5, -5, -5, 6, -5, -5)
#                     )
# x.init.4.3[nrow(x.init.4.3),] <- 0

x.init.4.3 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0),
                    c(6, -5, -5, -5, -5, 4, -3, -5),
                    c(6, -5, -5, -5, -5, 6, -5, -5),
                    c(6, -5, -5, -5, -5, 8, -3, -5),
                    c(6, -5, -5, -5, -5, 10, -5, -5),
                    c(6, -10, -10, -5, -5, 4, -3, -5),
                    c(6, -10, -10, -5, -5, 6, -5, -5),
                    c(6, -10, -10, -5, -5, 8, -3, -5),
                    c(6, -10, -10, -5, -5, 10, -5, -5)
                    )

rownames(x.init.4.3) <- loglikeSTnames(denver.model.4.3, all=FALSE)
x.init.4.3
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
## log.range.const.exp              0    6    6    6    6    6    6    6    6
## log.sill.const.exp               0   -5   -5   -5   -5  -10  -10  -10  -10
## log.nugget.const.exp             0   -5   -5   -5   -5  -10  -10  -10  -10
## log.nugget.V1.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## log.nugget.V2.iid                0   -5   -5   -5   -5   -5   -5   -5   -5
## nu.log.range.exp                 0    4    6    8   10    4    6    8   10
## nu.log.sill.exp                  0   -3   -5   -3   -5   -3   -5   -3   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5   -5   -5   -5   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.4.3 <- estimate.STmodel(denver.model.4.3, x.init.4.3)
## Optimisation using starting value 1/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       384.81  |proj g|=           15
## At iterate    10  f =      -1341.1  |proj g|=       0.49751
## At iterate    20  f =      -1343.1  |proj g|=        1.3717
## At iterate    30  f =      -1343.2  |proj g|=       0.48654
## At iterate    40  f =      -1343.2  |proj g|=       0.38361
## 
## iterations 42
## function evaluations 74
## segments explored during Cauchy searches 44
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.318876
## final function value -1343.19
## 
## F = -1343.19
## l(0) > u(0).  No feasible solutionfinal  value -1343.191708 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -977.38  |proj g|=           12
## At iterate    10  f =      -1341.5  |proj g|=       0.47926
## At iterate    20  f =      -1343.1  |proj g|=       0.21909
## 
## iterations 27
## function evaluations 43
## segments explored during Cauchy searches 29
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0722942
## final function value -1343.11
## 
## F = -1343.11
## l(0) > u(0).  No feasible solutionfinal  value -1343.111325 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 3/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1265.1  |proj g|=           10
## At iterate    10  f =      -1462.5  |proj g|=         8.558
## At iterate    20  f =      -1472.9  |proj g|=        8.8184
## 
## iterations 26
## function evaluations 39
## segments explored during Cauchy searches 29
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.0162177
## final function value -1514.13
## 
## F = -1514.13
## final  value -1514.125180 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1022.3  |proj g|=           12
## At iterate    10  f =        -1525  |proj g|=        1.9831
## At iterate    20  f =      -1529.8  |proj g|=        1.1516
## At iterate    30  f =      -1529.9  |proj g|=      0.015878
## 
## iterations 31
## function evaluations 48
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0158776
## final function value -1529.93
## 
## F = -1529.93
## final  value -1529.934115 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 5/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1356.9  |proj g|=           10
## At iterate    10  f =      -1527.5  |proj g|=        1.9166
## At iterate    20  f =      -1529.8  |proj g|=        1.1738
## At iterate    30  f =      -1529.9  |proj g|=       0.04797
## 
## iterations 31
## function evaluations 37
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0317846
## final function value -1529.93
## 
## F = -1529.93
## final  value -1529.934354 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 6/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -998.08  |proj g|=           12
## At iterate    10  f =      -1342.2  |proj g|=        1.3099
## At iterate    20  f =        -1343  |proj g|=        2.4442
## At iterate    30  f =      -1343.1  |proj g|=       0.48465
## At iterate    40  f =      -1343.2  |proj g|=       0.14304
## 
## iterations 40
## function evaluations 60
## segments explored during Cauchy searches 43
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.143042
## final function value -1343.15
## 
## F = -1343.15
## l(0) > u(0).  No feasible solutionfinal  value -1343.152843 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 7/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1297.6  |proj g|=           10
## At iterate    10  f =      -1467.4  |proj g|=        14.131
## At iterate    20  f =      -1497.2  |proj g|=        9.6985
## At iterate    30  f =      -1511.6  |proj g|=        0.4601
## At iterate    40  f =      -1512.4  |proj g|=        5.9573
## ys=-3.113e-01  -gs= 4.393e-01, BFGS update SKIPPED
## At iterate    50  f =      -1517.2  |proj g|=       0.09104
## At iterate    60  f =      -1517.2  |proj g|=      0.016027
## 
## iterations 62
## function evaluations 82
## segments explored during Cauchy searches 65
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00559225
## final function value -1517.2
## 
## F = -1517.2
## final  value -1517.201429 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 8/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1044.4  |proj g|=           12
## At iterate    10  f =        -1529  |proj g|=        2.8123
## At iterate    20  f =      -1529.9  |proj g|=        2.0939
## 
## iterations 27
## function evaluations 42
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0058536
## final function value -1529.93
## 
## F = -1529.93
## final  value -1529.933808 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 9/9
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1392.2  |proj g|=           10
## At iterate    10  f =        -1529  |proj g|=        1.7447
## At iterate    20  f =      -1529.8  |proj g|=        1.0912
## At iterate    30  f =      -1529.9  |proj g|=     0.0048336
## 
## iterations 32
## function evaluations 38
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00649365
## final function value -1529.93
## 
## F = -1529.93
## final  value -1529.933777 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
print(est.denver.model.4.3)
## Optimisation for STmodel with 9 starting points.
##   Results: 0 converged, 9 not converged, 0 failed.
##   Best result for starting point 5, optimisation has NOT converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                            [,1]            [,2]           [,3]
## gamma.bc_st_no2                   0.01349869090   0.01346867706   0.0166333287
## gamma.bc_st_smk                   0.07843172509   0.07858783928   0.0582141108
## alpha.const.(Intercept)           0.06597427121   0.06647372111   0.0332098371
## alpha.const.impervious_2500       0.05704143080   0.05602562657   0.0615168004
## alpha.const.open_2500             0.01997561821   0.01898515397   0.0251632677
## alpha.const.low_int_100           0.00936148629   0.00864307972   0.0174712626
## alpha.const.med_int_50            0.00459636002   0.00473220247  -0.0036718825
## alpha.const.high_int_50           0.01785301270   0.01780149529   0.0049311182
## alpha.const.high_int_100         -0.02375308597  -0.02374325441  -0.0004785960
## alpha.const.ag_250               -0.00333488145  -0.00342382459  -0.0028249521
## alpha.const.pop_den_50            0.00325880976   0.00330813712   0.0006704953
## alpha.const.dist_m_compost        0.00555415560   0.00555868562  -0.0001007666
## alpha.const.dist_m_military       0.01972376545   0.01985521832   0.0072571422
## alpha.const.len_m_highways_2500   0.00102179074   0.00119959352   0.0068553609
## alpha.const.aadt_100              0.03721211956   0.03691083401   0.0214099340
## alpha.const.aadt_2500            -0.00038295704  -0.00016497594  -0.0098783078
## alpha.V1.(Intercept)             -0.28070782200  -0.28108512087  -0.3096941429
## alpha.V1.impervious_2500         -0.05840101193  -0.05923547160  -0.0560681487
## alpha.V1.open_2500               -0.04258537838  -0.04332219471  -0.0427819442
## alpha.V1.low_int_100              0.00007700182  -0.00015760828  -0.0111527152
## alpha.V1.med_int_50              -0.00460118000  -0.00487816566  -0.0019389653
## alpha.V1.high_int_50              0.00948289059   0.00972509241   0.0071095662
## alpha.V1.high_int_100            -0.03372267060  -0.03430920039  -0.0299964740
## alpha.V1.ag_250                  -0.00871670800  -0.00968081941   0.0010692172
## alpha.V1.pop_den_50              -0.01319961660  -0.01326100161  -0.0074274573
## alpha.V1.dist_m_compost          -0.02451639260  -0.02527915356  -0.0105385219
## alpha.V1.dist_m_military         -0.01282435604  -0.01342872350   0.0049616223
## alpha.V1.len_m_highways_2500      0.00674898703   0.00670065332   0.0080398431
## alpha.V1.aadt_100                 0.01536736088   0.01473542392   0.0182293258
## alpha.V1.aadt_2500                0.00814750908   0.00785815411   0.0134982501
## alpha.V2.(Intercept)             -0.12752509962  -0.12796345679  -0.1118514138
## alpha.V2.impervious_2500         -0.01939830680  -0.02175187371  -0.0078611560
## alpha.V2.open_2500                0.00902813740   0.00708979951   0.0123227007
## alpha.V2.low_int_100              0.00417050490   0.00313564361  -0.0028707655
## alpha.V2.med_int_50              -0.00485883387  -0.00513562807  -0.0099033476
## alpha.V2.high_int_50             -0.00795722824  -0.00804477345  -0.0250486534
## alpha.V2.high_int_100            -0.03692946919  -0.03700291980  -0.0030033629
## alpha.V2.ag_250                  -0.02648248080  -0.02747901419  -0.0162027162
## alpha.V2.pop_den_50               0.00305872133   0.00304918889   0.0035456663
## alpha.V2.dist_m_compost           0.00608330456   0.00545593690   0.0203136237
## alpha.V2.dist_m_military          0.01209354119   0.01169498616   0.0245536523
## alpha.V2.len_m_highways_2500      0.01445264342   0.01476276316   0.0209111968
## alpha.V2.aadt_100                 0.00115290893  -0.00008861168  -0.0205731995
## alpha.V2.aadt_2500                0.00039599612   0.00035362634  -0.0021645294
## log.range.const.exp               0.00000000000   6.16593495825   6.0799042169
## log.sill.const.exp              -14.11672754786 -14.49180043442 -13.3209853241
## log.nugget.const.exp            -15.00000000000 -15.00000000000 -13.7281467454
## log.nugget.V1.iid                -8.67295852406 -12.09223842651 -14.8667399686
## log.nugget.V2.iid                -7.27397536824  -6.93355407708  -6.2143128564
## nu.log.range.exp                  0.00000000000   4.07469192525  15.0000000000
## nu.log.sill.exp                  -7.63339530037  -9.55896135629  -3.8186136611
## nu.log.nugget.(Intercept).exp    -4.56807555011  -4.52709301784  -5.5145981951
##                                           [,4]           [,5]            [,6]
## gamma.bc_st_no2                   0.0185383788   0.0185412024   0.01346789903
## gamma.bc_st_smk                   0.0536810230   0.0536768536   0.07847997282
## alpha.const.(Intercept)          -0.0101515413  -0.0102188507   0.06654945264
## alpha.const.impervious_2500       0.0647179696   0.0647125775   0.05641799997
## alpha.const.open_2500             0.0289377006   0.0289322939   0.01936364956
## alpha.const.low_int_100           0.0207085881   0.0207041120   0.00891025333
## alpha.const.med_int_50           -0.0053615243  -0.0053596682   0.00469048419
## alpha.const.high_int_50           0.0057701729   0.0057707150   0.01784123031
## alpha.const.high_int_100         -0.0003407701  -0.0003435669  -0.02378032485
## alpha.const.ag_250               -0.0014552535  -0.0014571428  -0.00338359283
## alpha.const.pop_den_50            0.0023775994   0.0023783899   0.00327656064
## alpha.const.dist_m_compost        0.0003459613   0.0003445508   0.00555660772
## alpha.const.dist_m_military       0.0064482490   0.0064490379   0.01981123820
## alpha.const.len_m_highways_2500   0.0053543719   0.0053545756   0.00115380632
## alpha.const.aadt_100              0.0221962146   0.0221939241   0.03705164802
## alpha.const.aadt_2500            -0.0102466307  -0.0102453138  -0.00025803966
## alpha.V1.(Intercept)             -0.2934989178  -0.2934872377  -0.28100144784
## alpha.V1.impervious_2500         -0.0570623375  -0.0570670563  -0.05897443662
## alpha.V1.open_2500               -0.0384500548  -0.0384607603  -0.04303356213
## alpha.V1.low_int_100             -0.0079311107  -0.0079345511  -0.00008651532
## alpha.V1.med_int_50              -0.0045651089  -0.0045638983  -0.00477942766
## alpha.V1.high_int_50             -0.0005737831  -0.0005672634   0.00961821552
## alpha.V1.high_int_100            -0.0131293422  -0.0131452258  -0.03407138900
## alpha.V1.ag_250                   0.0123460400   0.0123326912  -0.00925787586
## alpha.V1.pop_den_50              -0.0023715375  -0.0023776218  -0.01317714783
## alpha.V1.dist_m_compost          -0.0042851562  -0.0042963710  -0.02495042143
## alpha.V1.dist_m_military          0.0078913710   0.0078866128  -0.01317270647
## alpha.V1.len_m_highways_2500      0.0124494227   0.0124448607   0.00677822270
## alpha.V1.aadt_100                 0.0174111879   0.0174080925   0.01488385861
## alpha.V1.aadt_2500                0.0139773150   0.0139766693   0.00797594957
## alpha.V2.(Intercept)             -0.1073032608  -0.1073157840  -0.12782809956
## alpha.V2.impervious_2500         -0.0066343272  -0.0066406299  -0.02090240926
## alpha.V2.open_2500                0.0187407885   0.0187275863   0.00783878055
## alpha.V2.low_int_100              0.0041274377   0.0041192372   0.00348399888
## alpha.V2.med_int_50              -0.0155031400  -0.0154992087  -0.00500512157
## alpha.V2.high_int_50             -0.0334623038  -0.0334559777  -0.00796313498
## alpha.V2.high_int_100             0.0163591569   0.0163426570  -0.03710772020
## alpha.V2.ag_250                  -0.0042905685  -0.0043060492  -0.02702857254
## alpha.V2.pop_den_50               0.0086739788   0.0086675898   0.00306920220
## alpha.V2.dist_m_compost           0.0275772806   0.0275664064   0.00571516963
## alpha.V2.dist_m_military          0.0272836553   0.0272792849   0.01187282085
## alpha.V2.len_m_highways_2500      0.0250651535   0.0250606808   0.01474804563
## alpha.V2.aadt_100                -0.0207332494  -0.0207364414   0.00042352618
## alpha.V2.aadt_2500               -0.0021431867  -0.0021434369   0.00034191488
## log.range.const.exp               6.1210686001   6.1041792365   6.08740406333
## log.sill.const.exp              -15.0000000000 -14.9653688895 -14.76329511450
## log.nugget.const.exp            -14.9092602038 -15.0000000000 -15.00000000000
## log.nugget.V1.iid                -6.6229158006  -6.6251193708  -9.72980527999
## log.nugget.V2.iid                -6.0792244747  -6.0788611977  -7.00539464525
## nu.log.range.exp                 15.0000000000  15.0000000000   4.13625327698
## nu.log.sill.exp                  -3.8085380602  -3.8092418324  -7.53023553871
## nu.log.nugget.(Intercept).exp    -5.6749605388  -5.6746944636  -4.57269360809
##                                           [,7]           [,8]           [,9]
## gamma.bc_st_no2                   0.0179526590   0.0185396833   0.0185393494
## gamma.bc_st_smk                   0.0555889718   0.0536786570   0.0536792199
## alpha.const.(Intercept)          -0.0036317550  -0.0101828669  -0.0101750807
## alpha.const.impervious_2500       0.0461327896   0.0647164106   0.0647165892
## alpha.const.open_2500             0.0089201606   0.0289363922   0.0289364824
## alpha.const.low_int_100           0.0095063878   0.0207075595   0.0207074718
## alpha.const.med_int_50           -0.0087543660  -0.0053613204  -0.0053611573
## alpha.const.high_int_50           0.0014241759   0.0057702924   0.0057700871
## alpha.const.high_int_100          0.0027874760  -0.0003412368  -0.0003411018
## alpha.const.ag_250               -0.0018519401  -0.0014553664  -0.0014554207
## alpha.const.pop_den_50            0.0014616663   0.0023783765   0.0023781345
## alpha.const.dist_m_compost        0.0007274035   0.0003458347   0.0003459366
## alpha.const.dist_m_military       0.0107417933   0.0064484623   0.0064486120
## alpha.const.len_m_highways_2500   0.0130532835   0.0053543769   0.0053545405
## alpha.const.aadt_100              0.0152049684   0.0221954294   0.0221954512
## alpha.const.aadt_2500            -0.0060703124  -0.0102461050  -0.0102462294
## alpha.V1.(Intercept)             -0.2974533382  -0.2934914743  -0.2934941510
## alpha.V1.impervious_2500         -0.0469388499  -0.0570630652  -0.0570621161
## alpha.V1.open_2500               -0.0311236451  -0.0384510837  -0.0384507432
## alpha.V1.low_int_100             -0.0051555410  -0.0079310464  -0.0079313885
## alpha.V1.med_int_50              -0.0005479046  -0.0045652374  -0.0045647336
## alpha.V1.high_int_50              0.0046068773  -0.0005733839  -0.0005728670
## alpha.V1.high_int_100            -0.0240411972  -0.0131304023  -0.0131319493
## alpha.V1.ag_250                   0.0056009079   0.0123451046   0.0123446048
## alpha.V1.pop_den_50              -0.0043810701  -0.0023719496  -0.0023722120
## alpha.V1.dist_m_compost          -0.0071872818  -0.0042866976  -0.0042864871
## alpha.V1.dist_m_military          0.0057273870   0.0078905225   0.0078909151
## alpha.V1.len_m_highways_2500      0.0057794708   0.0124489278   0.0124485902
## alpha.V1.aadt_100                 0.0192567698   0.0174108336   0.0174109763
## alpha.V1.aadt_2500                0.0110582454   0.0139770219   0.0139771404
## alpha.V2.(Intercept)             -0.1121598481  -0.1073069009  -0.1073072159
## alpha.V2.impervious_2500         -0.0115750404  -0.0066353850  -0.0066344580
## alpha.V2.open_2500                0.0092898422   0.0187390440   0.0187395345
## alpha.V2.low_int_100             -0.0036375909   0.0041264339   0.0041260782
## alpha.V2.med_int_50              -0.0136969817  -0.0155029357  -0.0155023532
## alpha.V2.high_int_50             -0.0309195680  -0.0334621442  -0.0334617135
## alpha.V2.high_int_100             0.0069734754   0.0163582336   0.0163567868
## alpha.V2.ag_250                  -0.0115835044  -0.0042918986  -0.0042924043
## alpha.V2.pop_den_50               0.0061855507   0.0086734900   0.0086734471
## alpha.V2.dist_m_compost           0.0247573593   0.0275762316   0.0275763864
## alpha.V2.dist_m_military          0.0278244239   0.0272831032   0.0272833959
## alpha.V2.len_m_highways_2500      0.0239256670   0.0250647202   0.0250643828
## alpha.V2.aadt_100                -0.0245215422  -0.0207334746  -0.0207333908
## alpha.V2.aadt_2500               -0.0015742942  -0.0021431763  -0.0021432990
## log.range.const.exp               5.0249793712   6.0758069158   6.0750267213
## log.sill.const.exp               -7.0564724081 -14.8403058967 -14.8337523725
## log.nugget.const.exp            -15.0000000000 -15.0000000000 -15.0000000000
## log.nugget.V1.iid               -14.8958839617  -6.6230882734  -6.6232010666
## log.nugget.V2.iid                -6.6446378222  -6.0790939854  -6.0793234994
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8223387376  -3.8087644897  -3.8087159100
## nu.log.nugget.(Intercept).exp    -5.5637412153  -5.6749106446  -5.6749066661
## 
## Function value(s):
## [1] 1343.192 1343.111 1514.125 1529.934 1529.934 1343.153 1517.201 1529.934
## [9] 1529.934

9.4.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs2))
##  [1] "d_2"     "d_4"     "d_6"     "d_8"     "d_16"    "d_18"    "d_20"   
##  [8] "d_12"    "d_14"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_15"    "d_17"    "d_19"    "d_11"    "d_13"    "d_21"    "d_23"   
## [22] "d_25"    "d_28"    "d_30"    "d_32"    "d_40"    "d_41"    "d_42"   
## [29] "d_10"    "d_34"    "d_36"    "d_38"    "d_43"    "d_44"    "d_45"   
## [36] "d_3"     "d_1"     "d_27"    "d_29"    "d_31"    "d_39"    "d_9"    
## [43] "d_33"    "d_35"    "d_37"    "d_49"    "d_51"    "d_55"    "d_52"   
## [50] "d_56"    "d_50"    "d_54"    "d_46"    "d_47"    "d_53"    "d_48"   
## [57] "d_58"    "d_59"    "d_60"    "d_57"    "central"
Ind.cv.4.3 <- createCV(denver.model.4.3, groups = 10, #min.dist = .1,
                           subset = paste0("d_", c(1:60)))

ID.cv.4.3 <- sapply(split(denver.model.4.3$obs$ID, Ind.cv.4.3), unique)
print(sapply(ID.cv.4.3, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.4.3)
## Ind.cv.4.3
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.4.3 <- apply(sapply(ID.cv.4.3, function(x) denver.model.4.3$locations$ID%in% x), 1,
                       function(x) if(sum(x)==1) which(x) else 0)
names(I.col.4.3) <- denver.model.4.3$locations$ID
print(I.col.4.3)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.4.3$locations$long,
     denver.model.4.3$locations$lat,
     pch=23+floor(I.col.4.3/max(I.col.4.3)+.5), bg=I.col.4.3,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.4.3.cv <- coef(est.denver.model.4.3, pars="cov")[,c("par","init")]
x.init.4.3.cv

Run the model with cross validation

est.denver.4.3.cv <- estimateCV(denver.model.4.3, x.init.4.3.cv, Ind.cv.4.3)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1391.8  |proj g|=       2.0395
## 
## iterations 8
## function evaluations 19
## segments explored during Cauchy searches 8
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00858594
## final function value -1392.48
## 
## F = -1392.48
## final  value -1392.476704 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1230.9  |proj g|=           10
## At iterate    10  f =      -1387.7  |proj g|=        2.1539
## At iterate    20  f =      -1391.7  |proj g|=        1.4131
## At iterate    30  f =      -1392.5  |proj g|=       0.25904
## 
## iterations 37
## function evaluations 43
## segments explored during Cauchy searches 40
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00414794
## final function value -1392.48
## 
## F = -1392.48
## final  value -1392.476800 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1398.3  |proj g|=       2.5138
## At iterate    10  f =      -1398.3  |proj g|=     0.0040084
## 
## iterations 10
## function evaluations 13
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0040084
## final function value -1398.34
## 
## F = -1398.34
## final  value -1398.342097 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1240.2  |proj g|=           10
## At iterate    10  f =      -1394.5  |proj g|=        3.9703
## At iterate    20  f =      -1398.3  |proj g|=        1.5083
## At iterate    30  f =      -1398.3  |proj g|=      0.023801
## 
## iterations 31
## function evaluations 46
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0238007
## final function value -1398.34
## 
## F = -1398.34
## final  value -1398.342200 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1402.5  |proj g|=       2.5077
## 
## iterations 9
## function evaluations 29
## segments explored during Cauchy searches 9
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0503761
## final function value -1403.08
## 
## F = -1403.08
## l(0) > u(0).  No feasible solutionfinal  value -1403.076342 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        -1242  |proj g|=           10
## At iterate    10  f =      -1398.5  |proj g|=        3.8571
## At iterate    20  f =        -1403  |proj g|=         1.245
## 
## iterations 28
## function evaluations 40
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0109233
## final function value -1403.08
## 
## F = -1403.08
## final  value -1403.076440 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1365.6  |proj g|=       1.5204
## At iterate    10  f =      -1365.7  |proj g|=      0.075332
## 
## iterations 12
## function evaluations 18
## segments explored during Cauchy searches 12
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0378425
## final function value -1365.68
## 
## F = -1365.68
## final  value -1365.681758 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1209.4  |proj g|=           10
## At iterate    10  f =        -1361  |proj g|=         3.819
## At iterate    20  f =      -1365.6  |proj g|=       0.46021
## At iterate    30  f =      -1365.7  |proj g|=      0.035123
## 
## iterations 32
## function evaluations 43
## segments explored during Cauchy searches 35
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00449928
## final function value -1365.68
## 
## F = -1365.68
## final  value -1365.681859 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1378.7  |proj g|=        7.758
## At iterate    10  f =      -1379.3  |proj g|=      0.048894
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 12
## function evaluations 45
## segments explored during Cauchy searches 13
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0664319
## final function value -1379.28
## 
## F = -1379.28
## l(0) > u(0).  No feasible solutionfinal  value -1379.281105 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1223.9  |proj g|=           10
## At iterate    10  f =      -1373.1  |proj g|=        4.3198
## At iterate    20  f =      -1379.2  |proj g|=       0.30532
## At iterate    30  f =      -1379.3  |proj g|=        0.2482
## 
## iterations 34
## function evaluations 38
## segments explored during Cauchy searches 37
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.002493
## final function value -1379.28
## 
## F = -1379.28
## final  value -1379.281225 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1413.3  |proj g|=       5.5914
## At iterate    10  f =      -1413.4  |proj g|=     0.0050647
## 
## iterations 10
## function evaluations 12
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00506471
## final function value -1413.42
## 
## F = -1413.42
## final  value -1413.421603 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1256.3  |proj g|=           10
## At iterate    10  f =      -1407.3  |proj g|=        4.1473
## At iterate    20  f =      -1413.3  |proj g|=       0.81506
## 
## iterations 27
## function evaluations 31
## segments explored during Cauchy searches 30
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00763156
## final function value -1413.42
## 
## F = -1413.42
## final  value -1413.421450 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1404.6  |proj g|=       4.3915
## At iterate    10  f =      -1405.1  |proj g|=     0.0064268
## 
## iterations 12
## function evaluations 15
## segments explored during Cauchy searches 12
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00661312
## final function value -1405.12
## 
## F = -1405.12
## final  value -1405.123210 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1248.1  |proj g|=           10
## At iterate    10  f =      -1400.9  |proj g|=        8.2206
## At iterate    20  f =      -1404.5  |proj g|=         1.514
## At iterate    30  f =      -1405.1  |proj g|=      0.063439
## 
## iterations 33
## function evaluations 51
## segments explored during Cauchy searches 36
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0081476
## final function value -1405.12
## 
## F = -1405.12
## l(0) > u(0).  No feasible solutionfinal  value -1405.123206 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1399.7  |proj g|=         3.14
## At iterate    10  f =      -1399.8  |proj g|=     0.0038074
## 
## iterations 10
## function evaluations 14
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00380745
## final function value -1399.76
## 
## F = -1399.76
## final  value -1399.756518 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1239.5  |proj g|=           10
## At iterate    10  f =      -1395.6  |proj g|=        4.3763
## At iterate    20  f =      -1399.6  |proj g|=       0.49618
## At iterate    30  f =      -1399.8  |proj g|=     0.0040752
## 
## iterations 31
## function evaluations 38
## segments explored during Cauchy searches 34
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0361954
## final function value -1399.76
## 
## F = -1399.76
## final  value -1399.756409 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1402.7  |proj g|=       4.4117
## At iterate    10  f =      -1402.7  |proj g|=      0.033548
## 
## iterations 10
## function evaluations 14
## segments explored during Cauchy searches 10
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0335477
## final function value -1402.71
## 
## F = -1402.71
## final  value -1402.705604 
## converged
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1244.2  |proj g|=           10
## At iterate    10  f =      -1398.3  |proj g|=        5.8988
## At iterate    20  f =      -1402.6  |proj g|=        1.3396
## 
## iterations 29
## function evaluations 34
## segments explored during Cauchy searches 32
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0350482
## final function value -1402.71
## 
## F = -1402.71
## final  value -1402.705653 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=        -1390  |proj g|=       1.0461
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## Line search cannot locate an adequate point after 20 function
## and gradient evaluations
## final  value -1390.046473 
## stopped after 7 iterations
## 
## Optimisation using starting value 2/2
## N = 8, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1232.9  |proj g|=           10
## At iterate    10  f =      -1385.4  |proj g|=        2.9438
## At iterate    20  f =      -1389.9  |proj g|=          0.42
## 
## iterations 28
## function evaluations 46
## segments explored during Cauchy searches 31
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00591305
## final function value -1390.05
## 
## F = -1390.05
## l(0) > u(0).  No feasible solutionfinal  value -1390.046521 
## converged
## 
print(est.denver.4.3.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 9 converged, 1 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv       eigen.min eigen.all.min
## 1  1392.477        TRUE  TRUE  0.000224062147            NA
## 2  1398.342        TRUE FALSE -0.000058430618            NA
## 3  1403.076        TRUE  TRUE  0.000077631883            NA
## 4  1365.682        TRUE  TRUE  0.000088183401            NA
## 5  1379.281        TRUE  TRUE  0.000004243289            NA
## 6  1413.422        TRUE  TRUE  0.000091612921            NA
## 7  1405.123        TRUE  TRUE  0.000086069994            NA
## 8  1399.757        TRUE  TRUE  0.000102716697            NA
## 9  1402.706        TRUE  TRUE  0.000036830532            NA
## 10 1390.047        TRUE  TRUE  0.000174036373            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.4.3, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
             col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.4.3.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data4.2, denver.model.4.3, est.denver.model.4.3, est.denver.4.3.cv,
     file = here::here("Results", "Denver_ST_Model_4.3.rdata"))

9.4.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.4.3.cv <- predictCV(denver.model.4.3, est.denver.4.3.cv, LTA = T)
pred.4.3.cv.log <- predictCV(denver.model.4.3, est.denver.4.3.cv,
                             LTA = T, transform="unbiased")

names(pred.4.3.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.4.3.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.11380536 0.11380527 0.09276479
## average 0.07164641 0.07164626 0.06266527
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6950109  0.6950113 0.7973599
## average 0.7751741  0.7751750 0.8280068
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9205835
## average 0.9166667
summary(pred.4.3.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.13731479  0.1373147 0.10713027 0.10729199
## average 0.08264782  0.0826476 0.07007933 0.07043896
## 
## R2:
##             EX.mu EX.mu.beta        EX   EX.pred
## obs     0.7080366  0.7080370 0.8222874 0.8217505
## average 0.8162109  0.8162119 0.8678593 0.8664996
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9205835
## average 0.9333333
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.3.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.3.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod4.3.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.3.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.3.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

9.5 Model 4.4: Smoothing for beta1, beta2 and the error term

9.5.1 Create the model object

For this version of the model, use iid for cov.beta (beta0) and exp for cov.beta (beta1, beta2) cov.nu (error).

names(denver.data4.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR4.4 <- list(covar_fun, covar_fun, covar_fun)

cov.beta4.4 <-  list(covf=c("iid", "exp", "exp"), nugget = c(TRUE, TRUE, TRUE))
cov.nu4.4 <- list(covf="exp", nugget = T, random.effect = FALSE)
locations4.4 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.4.4 <- createSTmodel(denver.data4.2, LUR = LUR4.4,
                                  ST = c("bc_st_no2", "bc_st_smk"),
                                  cov.beta = cov.beta4.4, cov.nu = cov.nu4.4,
                                  locations = locations4.4)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.4.4
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): iid, exp, exp 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

9.5.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.4.4, all=FALSE)
names
##  [1] "log.nugget.const.iid"          "log.range.V1.exp"             
##  [3] "log.sill.V1.exp"               "log.nugget.V1.exp"            
##  [5] "log.range.V2.exp"              "log.sill.V2.exp"              
##  [7] "log.nugget.V2.exp"             "nu.log.range.exp"             
##  [9] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# 
# x.init.4.4 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
#                     c(-1, 0, -1, -1, 0, -1, -1, 0, -1, -1),
#                     c(-1, 0, -1, -5, 0, -5, -1, 0, -5, -1),
#                     c(-5, 0, -5, -1, 0, -1, -5, 0, -1, -5),
#                     c(-5, 0, -5, -5, 0, -5, -5, 0, -5, -5),
#                     c(-1, 2, -1, -1, 2, -1, -1, 2, -1, -1),
#                     c(-1, 2, -1, -5, 2, -5, -1, 2, -5, -1),
#                     c(-5, 2, -5, -1, 2, -1, -5, 2, -1, -5),
#                     c(-5, 2, -5, -5, 2, -5, -5, 2, -5, -5),
#                     c(-1, 4, -1, -1, 4, -1, -1, 4, -1, -1),
#                     c(-1, 4, -1, -5, 4, -5, -1, 4, -5, -1),
#                     c(-5, 4, -5, -5, 4, -1, -5, 4, -1, -5),
#                     c(-5, 4, -5, -5, 4, -5, -5, 4, -5, -5),
#                     c(-1, 6, -1, -1, 6, -1, -1, 6, -1, -1),
#                     c(-1, 6, -1, -5, 6, -5, -1, 6, -5, -1),
#                     c(-5, 6, -5, -5, 6, -1, -5, 6, -1, -5),
#                     c(-5, 6, -5, -5, 6, -5, -5, 6, -5, -5))
# x.init.4.4[nrow(x.init.4.4),] <- 0

x.init.4.4 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                    c(-5, 4, -5, -5, 6, -5, -5, 6, -5, -5),
                    c(-5, 4, -5, -5, 6, -5, -5, 6, -5, -5),
                    c(-10, 4, -10, -1, 6, -5, -10, 10, -5, -5),
                    c(-10, 4, -10, -5, 6, -5, -10, 10 -5, -5),
                    c(-13, 4, -10, -1, 6, -5, -13, 10, -5, -5),
                    c(-13, 4, -10, -5, 6, -5, -13, 10, -5, -5))
## Warning in cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), c(-5, 4, -5, -5, 6, -5, :
## number of rows of result is not a multiple of vector length (arg 5)
rownames(x.init.4.4) <- loglikeSTnames(denver.model.4.4, all=FALSE)
x.init.4.4
##                               [,1] [,2] [,3] [,4] [,5] [,6] [,7]
## log.nugget.const.iid             0   -5   -5  -10  -10  -13  -13
## log.range.V1.exp                 0    4    4    4    4    4    4
## log.sill.V1.exp                  0   -5   -5  -10  -10  -10  -10
## log.nugget.V1.exp                0   -5   -5   -1   -5   -1   -5
## log.range.V2.exp                 0    6    6    6    6    6    6
## log.sill.V2.exp                  0   -5   -5   -5   -5   -5   -5
## log.nugget.V2.exp                0   -5   -5  -10  -10  -13  -13
## nu.log.range.exp                 0    6    6   10    5   10   10
## nu.log.sill.exp                  0   -5   -5   -5   -5   -5   -5
## nu.log.nugget.(Intercept).exp    0   -5   -5   -5  -10   -5   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.4.4 <- estimate.STmodel(denver.model.4.4, x.init.4.4)
## Optimisation using starting value 1/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=       395.01  |proj g|=           15
## At iterate    10  f =      -1342.9  |proj g|=       0.16236
## At iterate    20  f =      -1343.1  |proj g|=         0.108
## At iterate    30  f =      -1343.2  |proj g|=       0.18437
## At iterate    40  f =      -1343.2  |proj g|=       0.17119
## At iterate    50  f =      -1343.2  |proj g|=       0.44999
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 54
## function evaluations 103
## segments explored during Cauchy searches 57
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.142626
## final function value -1343.18
## 
## F = -1343.18
## final  value -1343.183788 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1259.4  |proj g|=           10
## At iterate    10  f =      -1521.6  |proj g|=        9.4948
## At iterate    20  f =      -1530.1  |proj g|=        6.0323
## At iterate    30  f =      -1530.9  |proj g|=       0.48434
## At iterate    40  f =        -1531  |proj g|=       0.11974
## At iterate    50  f =      -1531.1  |proj g|=        0.2341
## At iterate    60  f =      -1531.2  |proj g|=       0.29124
## 
## iterations 65
## function evaluations 84
## segments explored during Cauchy searches 68
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0148404
## final function value -1531.16
## 
## F = -1531.16
## final  value -1531.162126 
## converged
## Optimisation using starting value 3/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1259.4  |proj g|=           10
## At iterate    10  f =      -1521.6  |proj g|=        9.4948
## At iterate    20  f =      -1530.1  |proj g|=        6.0323
## At iterate    30  f =      -1530.9  |proj g|=       0.48434
## At iterate    40  f =        -1531  |proj g|=       0.11974
## At iterate    50  f =      -1531.1  |proj g|=        0.2341
## At iterate    60  f =      -1531.2  |proj g|=       0.29124
## 
## iterations 65
## function evaluations 84
## segments explored during Cauchy searches 68
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0148404
## final function value -1531.16
## 
## F = -1531.16
## final  value -1531.162126 
## converged
## Optimisation using starting value 4/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1293.2  |proj g|=           14
## At iterate    10  f =      -1530.1  |proj g|=        3.8181
## At iterate    20  f =      -1530.8  |proj g|=        0.9177
## At iterate    30  f =        -1531  |proj g|=       0.37291
## At iterate    40  f =      -1531.1  |proj g|=       0.45412
## At iterate    50  f =      -1531.1  |proj g|=      0.021489
## At iterate    60  f =      -1531.2  |proj g|=       0.57539
## At iterate    70  f =      -1531.2  |proj g|=      0.060678
## 
## iterations 77
## function evaluations 91
## segments explored during Cauchy searches 80
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0334008
## final function value -1531.16
## 
## F = -1531.16
## final  value -1531.161342 
## converged
## Optimisation using starting value 5/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -84.999  |proj g|=           25
## At iterate    10  f =      -1343.3  |proj g|=        1.7277
## At iterate    20  f =      -1526.8  |proj g|=        5.5671
## At iterate    30  f =      -1530.8  |proj g|=        2.3569
## At iterate    40  f =        -1531  |proj g|=       0.64714
## At iterate    50  f =      -1531.1  |proj g|=      0.020073
## 
## iterations 51
## function evaluations 62
## segments explored during Cauchy searches 54
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0148737
## final function value -1531.14
## 
## F = -1531.14
## final  value -1531.143745 
## converged
## Optimisation using starting value 6/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1293.6  |proj g|=           14
## At iterate    10  f =        -1531  |proj g|=        1.5211
## At iterate    20  f =      -1531.1  |proj g|=       0.13137
## At iterate    30  f =      -1531.1  |proj g|=        0.3613
## At iterate    40  f =      -1531.2  |proj g|=       0.15161
## 
## iterations 49
## function evaluations 77
## segments explored during Cauchy searches 52
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0298061
## final function value -1531.16
## 
## F = -1531.16
## l(0) > u(0).  No feasible solutionfinal  value -1531.155574 
## converged
## Optimisation using starting value 7/7
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1393.7  |proj g|=           10
## At iterate    10  f =        -1531  |proj g|=        2.1801
## At iterate    20  f =      -1531.1  |proj g|=       0.05495
## At iterate    30  f =      -1531.1  |proj g|=       0.76151
## At iterate    40  f =      -1531.2  |proj g|=       0.23474
## 
## iterations 48
## function evaluations 59
## segments explored during Cauchy searches 51
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0211295
## final function value -1531.16
## 
## F = -1531.16
## final  value -1531.155566 
## converged
print(est.denver.model.4.4)
## Optimisation for STmodel with 7 starting points.
##   Results: 6 converged, 1 not converged, 0 failed.
##   Best result for starting point 2, optimisation has converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                            [,1]           [,2]           [,3]
## gamma.bc_st_no2                   0.01349006138   0.0185097131   0.0185097131
## gamma.bc_st_smk                   0.07842701032   0.0544483869   0.0544483869
## alpha.const.(Intercept)           0.06618086146  -0.0097001181  -0.0097001181
## alpha.const.impervious_2500       0.05704056077   0.0650529710   0.0650529710
## alpha.const.open_2500             0.01997855419   0.0292033865   0.0292033865
## alpha.const.low_int_100           0.00936727365   0.0208662579   0.0208662579
## alpha.const.med_int_50            0.00462146969  -0.0054976813  -0.0054976813
## alpha.const.high_int_50           0.01787056286   0.0058557464   0.0058557464
## alpha.const.high_int_100         -0.02377941025  -0.0003984034  -0.0003984034
## alpha.const.ag_250               -0.00333567485  -0.0013561560  -0.0013561560
## alpha.const.pop_den_50            0.00324646763   0.0023643021   0.0023643021
## alpha.const.dist_m_compost        0.00554870298   0.0002890469   0.0002890469
## alpha.const.dist_m_military       0.01969955212   0.0063812157   0.0063812157
## alpha.const.len_m_highways_2500   0.00102435186   0.0052425710   0.0052425710
## alpha.const.aadt_100              0.03723860161   0.0223721005   0.0223721005
## alpha.const.aadt_2500            -0.00039229436  -0.0101738615  -0.0101738615
## alpha.V1.(Intercept)             -0.28074841158  -0.2913439955  -0.2913439955
## alpha.V1.impervious_2500         -0.05834904155  -0.0569856532  -0.0569856532
## alpha.V1.open_2500               -0.04259089977  -0.0382783173  -0.0382783173
## alpha.V1.low_int_100              0.00005436535  -0.0075366927  -0.0075366927
## alpha.V1.med_int_50              -0.00459928385  -0.0047027804  -0.0047027804
## alpha.V1.high_int_50              0.00951354838  -0.0004092178  -0.0004092178
## alpha.V1.high_int_100            -0.03383403020  -0.0128306583  -0.0128306583
## alpha.V1.ag_250                  -0.00875867800   0.0130186251   0.0130186251
## alpha.V1.pop_den_50              -0.01319962412  -0.0026409289  -0.0026409289
## alpha.V1.dist_m_compost          -0.02454917671  -0.0043800799  -0.0043800799
## alpha.V1.dist_m_military         -0.01283027181   0.0077489226   0.0077489226
## alpha.V1.len_m_highways_2500      0.00671598583   0.0122484785   0.0122484785
## alpha.V1.aadt_100                 0.01536823133   0.0182187587   0.0182187587
## alpha.V1.aadt_2500                0.00813777338   0.0142305101   0.0142305101
## alpha.V2.(Intercept)             -0.12746118828  -0.1037017842  -0.1037017842
## alpha.V2.impervious_2500         -0.01921827913  -0.0031910195  -0.0031910195
## alpha.V2.open_2500                0.00910276822   0.0217458802   0.0217458802
## alpha.V2.low_int_100              0.00413788184   0.0053099710   0.0053099710
## alpha.V2.med_int_50              -0.00477358829  -0.0145599170  -0.0145599170
## alpha.V2.high_int_50             -0.00776390210  -0.0306295194  -0.0306295194
## alpha.V2.high_int_100            -0.03736112689   0.0140425031   0.0140425031
## alpha.V2.ag_250                  -0.02652502153  -0.0026897557  -0.0026897557
## alpha.V2.pop_den_50               0.00304863658   0.0070941049   0.0070941049
## alpha.V2.dist_m_compost           0.00601599179   0.0263742709   0.0263742709
## alpha.V2.dist_m_military          0.01204486512   0.0274401441   0.0274401441
## alpha.V2.len_m_highways_2500      0.01439680138   0.0227205327   0.0227205327
## alpha.V2.aadt_100                 0.00139025878  -0.0177172534  -0.0177172534
## alpha.V2.aadt_2500                0.00038600059  -0.0009299509  -0.0009299509
## log.nugget.const.iid            -15.00000000000 -15.0000000000 -15.0000000000
## log.range.V1.exp                  0.00000000000   3.9498280195   3.9498280195
## log.sill.V1.exp                 -11.75573140863 -13.6552254443 -13.6552254443
## log.nugget.V1.exp                -8.70510733984  -6.6097738856  -6.6097738856
## log.range.V2.exp                  0.00000000000   6.4091838744   6.4091838744
## log.sill.V2.exp                 -10.75227636358  -6.0446206987  -6.0446206987
## log.nugget.V2.exp                -7.33201329470 -14.8220350304 -14.8220350304
## nu.log.range.exp                  0.00000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -7.41942101248  -3.8075514756  -3.8075514756
## nu.log.nugget.(Intercept).exp    -4.57940608377  -5.6799664264  -5.6799664264
##                                           [,4]           [,5]           [,6]
## gamma.bc_st_no2                   0.0185087389   0.0185079121   0.0185101591
## gamma.bc_st_smk                   0.0544560120   0.0545026367   0.0544651390
## alpha.const.(Intercept)          -0.0096755095  -0.0096129663  -0.0096946827
## alpha.const.impervious_2500       0.0650499509   0.0650529791   0.0650515184
## alpha.const.open_2500             0.0291999487   0.0292050313   0.0292030162
## alpha.const.low_int_100           0.0208635323   0.0208670213   0.0208664934
## alpha.const.med_int_50           -0.0054969758  -0.0054993825  -0.0054984585
## alpha.const.high_int_50           0.0058549677   0.0058508769   0.0058542180
## alpha.const.high_int_100         -0.0003981970  -0.0003901320  -0.0003951479
## alpha.const.ag_250               -0.0013579146  -0.0013529836  -0.0013551759
## alpha.const.pop_den_50            0.0023632323   0.0023679058   0.0023659787
## alpha.const.dist_m_compost        0.0002885655   0.0002916957   0.0002898664
## alpha.const.dist_m_military       0.0063820080   0.0063830738   0.0063815013
## alpha.const.len_m_highways_2500   0.0052441006   0.0052453806   0.0052436109
## alpha.const.aadt_100              0.0223702700   0.0223609103   0.0223674439
## alpha.const.aadt_2500            -0.0101735759  -0.0101746691  -0.0101740523
## alpha.V1.(Intercept)             -0.2913445828  -0.2913007132  -0.2913223931
## alpha.V1.impervious_2500         -0.0569889834  -0.0570154637  -0.0569969198
## alpha.V1.open_2500               -0.0382862947  -0.0382909353  -0.0382830917
## alpha.V1.low_int_100             -0.0075406097  -0.0075420424  -0.0075384480
## alpha.V1.med_int_50              -0.0047012543  -0.0047192805  -0.0047087475
## alpha.V1.high_int_50             -0.0004060207  -0.0004702957  -0.0004317292
## alpha.V1.high_int_100            -0.0128404412  -0.0127367366  -0.0127952910
## alpha.V1.ag_250                   0.0130070091   0.0130394759   0.0130255257
## alpha.V1.pop_den_50              -0.0026444870  -0.0026030808  -0.0026274365
## alpha.V1.dist_m_compost          -0.0043863928  -0.0043541733  -0.0043712859
## alpha.V1.dist_m_military          0.0077471698   0.0077726562   0.0077569077
## alpha.V1.len_m_highways_2500      0.0122457689   0.0122642500   0.0122541986
## alpha.V1.aadt_100                 0.0182119031   0.0180943949   0.0181745038
## alpha.V1.aadt_2500                0.0142297894   0.0142282801   0.0142292458
## alpha.V2.(Intercept)             -0.1036751799  -0.1034480307  -0.1036117381
## alpha.V2.impervious_2500         -0.0031982717  -0.0032096067  -0.0032039498
## alpha.V2.open_2500                0.0217310884   0.0217373673   0.0217352023
## alpha.V2.low_int_100              0.0052989856   0.0052989158   0.0053016867
## alpha.V2.med_int_50              -0.0145567322  -0.0145689931  -0.0145636905
## alpha.V2.high_int_50             -0.0306243472  -0.0306839789  -0.0306514132
## alpha.V2.high_int_100             0.0140253474   0.0141117763   0.0140679878
## alpha.V2.ag_250                  -0.0027053182  -0.0026669851  -0.0026859041
## alpha.V2.pop_den_50               0.0070892675   0.0071296156   0.0071058073
## alpha.V2.dist_m_compost           0.0263675888   0.0264005827   0.0263846757
## alpha.V2.dist_m_military          0.0274384374   0.0274661886   0.0274486201
## alpha.V2.len_m_highways_2500      0.0227213297   0.0227413648   0.0227319831
## alpha.V2.aadt_100                -0.0177220698  -0.0178179464  -0.0177528555
## alpha.V2.aadt_2500               -0.0009339855  -0.0009322420  -0.0009345667
## log.nugget.const.iid            -15.0000000000 -15.0000000000 -15.0000000000
## log.range.V1.exp                  3.9782106322   3.9925520882   3.9926478698
## log.sill.V1.exp                 -12.3445894477  -9.7711014460 -10.7650205409
## log.nugget.V1.exp                -6.6137662308  -6.6502413034  -6.6237848893
## log.range.V2.exp                  6.4070481584   6.4091468393   6.4067784422
## log.sill.V2.exp                  -6.0443944530  -6.0459374843  -6.0448139331
## log.nugget.V2.exp               -15.0000000000 -12.2346492846 -13.1216155618
## nu.log.range.exp                 15.0000000000  15.0000000000  15.0000000000
## nu.log.sill.exp                  -3.8075531125  -3.8073132662  -3.8075471428
## nu.log.nugget.(Intercept).exp    -5.6798343619  -5.6801310817  -5.6799527904
##                                           [,7]
## gamma.bc_st_no2                   0.0185112069
## gamma.bc_st_smk                   0.0544633158
## alpha.const.(Intercept)          -0.0097194446
## alpha.const.impervious_2500       0.0650501976
## alpha.const.open_2500             0.0292020033
## alpha.const.low_int_100           0.0208660552
## alpha.const.med_int_50           -0.0054983917
## alpha.const.high_int_50           0.0058544410
## alpha.const.high_int_100         -0.0003953343
## alpha.const.ag_250               -0.0013553845
## alpha.const.pop_den_50            0.0023664152
## alpha.const.dist_m_compost        0.0002896809
## alpha.const.dist_m_military       0.0063813611
## alpha.const.len_m_highways_2500   0.0052435872
## alpha.const.aadt_100              0.0223668548
## alpha.const.aadt_2500            -0.0101738326
## alpha.V1.(Intercept)             -0.2913158950
## alpha.V1.impervious_2500         -0.0569977123
## alpha.V1.open_2500               -0.0382840399
## alpha.V1.low_int_100             -0.0075385713
## alpha.V1.med_int_50              -0.0047087667
## alpha.V1.high_int_50             -0.0004317522
## alpha.V1.high_int_100            -0.0127952953
## alpha.V1.ag_250                   0.0130243401
## alpha.V1.pop_den_50              -0.0026277882
## alpha.V1.dist_m_compost          -0.0043724369
## alpha.V1.dist_m_military          0.0077562262
## alpha.V1.len_m_highways_2500      0.0122539731
## alpha.V1.aadt_100                 0.0181742606
## alpha.V1.aadt_2500                0.0142288880
## alpha.V2.(Intercept)             -0.1036115767
## alpha.V2.impervious_2500         -0.0032077044
## alpha.V2.open_2500                0.0217301487
## alpha.V2.low_int_100              0.0052987112
## alpha.V2.med_int_50              -0.0145637392
## alpha.V2.high_int_50             -0.0306521303
## alpha.V2.high_int_100             0.0140670654
## alpha.V2.ag_250                  -0.0026892612
## alpha.V2.pop_den_50               0.0071048474
## alpha.V2.dist_m_compost           0.0263843960
## alpha.V2.dist_m_military          0.0274478713
## alpha.V2.len_m_highways_2500      0.0227337962
## alpha.V2.aadt_100                -0.0177528242
## alpha.V2.aadt_2500               -0.0009366550
## log.nugget.const.iid            -15.0000000000
## log.range.V1.exp                  3.9927998821
## log.sill.V1.exp                 -10.7652791238
## log.nugget.V1.exp                -6.6238808723
## log.range.V2.exp                  6.4054864810
## log.sill.V2.exp                  -6.0446870288
## log.nugget.V2.exp               -13.1210822392
## nu.log.range.exp                 15.0000000000
## nu.log.sill.exp                  -3.8077682233
## nu.log.nugget.(Intercept).exp    -5.6799744651
## 
## Function value(s):
## [1] 1343.184 1531.162 1531.162 1531.161 1531.144 1531.156 1531.156

9.5.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs2))
##  [1] "d_2"     "d_4"     "d_6"     "d_8"     "d_16"    "d_18"    "d_20"   
##  [8] "d_12"    "d_14"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_15"    "d_17"    "d_19"    "d_11"    "d_13"    "d_21"    "d_23"   
## [22] "d_25"    "d_28"    "d_30"    "d_32"    "d_40"    "d_41"    "d_42"   
## [29] "d_10"    "d_34"    "d_36"    "d_38"    "d_43"    "d_44"    "d_45"   
## [36] "d_3"     "d_1"     "d_27"    "d_29"    "d_31"    "d_39"    "d_9"    
## [43] "d_33"    "d_35"    "d_37"    "d_49"    "d_51"    "d_55"    "d_52"   
## [50] "d_56"    "d_50"    "d_54"    "d_46"    "d_47"    "d_53"    "d_48"   
## [57] "d_58"    "d_59"    "d_60"    "d_57"    "central"
Ind.cv.4.4 <- createCV(denver.model.4.4, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.4.4 <- sapply(split(denver.model.4.4$obs$ID, Ind.cv.4.4), unique)
print(sapply(ID.cv.4.4, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.4.4)
## Ind.cv.4.4
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.4.4 <- apply(sapply(ID.cv.4.4,function(x) denver.model.4.4$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.4.4) <- denver.model.4.4$locations$ID
print(I.col.4.4)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.4.4$locations$long,
     denver.model.4.4$locations$lat,
     pch=23+floor(I.col.4.4/max(I.col.4.4)+.5), bg=I.col.4.4,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.4.4.cv <- coef(est.denver.model.4.4, pars="cov")[,c("par","init")]
x.init.4.4.cv

Run the model with cross validation.

est.denver.4.4.cv <- estimateCV(denver.model.4.4, x.init.4.4.cv, Ind.cv.4.4)
## 
## ***************************
## Estimation of CV-set 1/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1392.8  |proj g|=       2.0744
## 
## iterations 7
## function evaluations 10
## segments explored during Cauchy searches 7
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0147314
## final function value -1393.44
## 
## F = -1393.44
## final  value -1393.438131 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1144.2  |proj g|=           10
## At iterate    10  f =      -1349.3  |proj g|=        11.413
## At iterate    20  f =      -1392.3  |proj g|=        2.3549
## At iterate    30  f =      -1393.2  |proj g|=       0.89933
## At iterate    40  f =      -1393.3  |proj g|=       0.22194
## At iterate    50  f =      -1393.4  |proj g|=       0.11982
## At iterate    60  f =      -1393.4  |proj g|=       0.24253
## At iterate    70  f =      -1393.4  |proj g|=      0.066889
## 
## iterations 73
## function evaluations 90
## segments explored during Cauchy searches 76
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00841293
## final function value -1393.44
## 
## F = -1393.44
## final  value -1393.436512 
## converged
## 
## 
## ***************************
## Estimation of CV-set 2/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1399.7  |proj g|=        2.738
## At iterate    10  f =      -1399.8  |proj g|=       0.01047
## 
## iterations 15
## function evaluations 31
## segments explored during Cauchy searches 15
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0198301
## final function value -1399.76
## 
## F = -1399.76
## l(0) > u(0).  No feasible solutionfinal  value -1399.760778 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1154.8  |proj g|=           10
## At iterate    10  f =      -1338.6  |proj g|=        9.5916
## At iterate    20  f =      -1386.6  |proj g|=         1.474
## At iterate    30  f =      -1397.7  |proj g|=        2.6018
## At iterate    40  f =      -1398.3  |proj g|=        2.7135
## At iterate    50  f =      -1398.4  |proj g|=       0.64463
## At iterate    60  f =      -1398.6  |proj g|=       0.31079
## At iterate    70  f =      -1398.8  |proj g|=       0.78002
## ys=-5.430e-02  -gs= 1.144e-01, BFGS update SKIPPED
## At iterate    80  f =      -1399.5  |proj g|=        2.0552
## 
## iterations 88
## function evaluations 125
## segments explored during Cauchy searches 91
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.019352
## final function value -1399.76
## 
## F = -1399.76
## final  value -1399.761100 
## converged
## 
## 
## ***************************
## Estimation of CV-set 3/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1403.3  |proj g|=       2.7052
## At iterate    10  f =      -1403.8  |proj g|=       0.18861
## Bad direction in the line search;
##    refresh the lbfgs memory and restart the iteration.
## 
## iterations 19
## function evaluations 59
## segments explored during Cauchy searches 20
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00275694
## final function value -1403.81
## 
## F = -1403.81
## l(0) > u(0).  No feasible solutionfinal  value -1403.813839 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1154.8  |proj g|=           10
## At iterate    10  f =      -1352.5  |proj g|=         7.978
## At iterate    20  f =        -1393  |proj g|=        20.602
## At iterate    30  f =      -1400.4  |proj g|=        9.5283
## At iterate    40  f =        -1403  |proj g|=       0.59294
## At iterate    50  f =      -1403.1  |proj g|=       0.68542
## ys=-9.669e-03  -gs= 4.458e-02, BFGS update SKIPPED
## At iterate    60  f =      -1403.2  |proj g|=       0.16193
## At iterate    70  f =      -1403.5  |proj g|=       0.50204
## At iterate    80  f =      -1403.8  |proj g|=       0.28903
## 
## iterations 85
## function evaluations 99
## segments explored during Cauchy searches 88
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0297518
## final function value -1403.81
## 
## F = -1403.81
## final  value -1403.805949 
## converged
## 
## 
## ***************************
## Estimation of CV-set 4/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1366.7  |proj g|=       1.5261
## At iterate    10  f =      -1367.3  |proj g|=        3.6523
## At iterate    20  f =      -1367.8  |proj g|=    0.00051829
## 
## iterations 20
## function evaluations 28
## segments explored during Cauchy searches 20
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.000518294
## final function value -1367.81
## 
## F = -1367.81
## final  value -1367.807507 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1125.5  |proj g|=           10
## At iterate    10  f =      -1285.9  |proj g|=        9.5048
## At iterate    20  f =      -1337.8  |proj g|=        20.513
## At iterate    30  f =      -1356.1  |proj g|=        19.275
## At iterate    40  f =      -1365.6  |proj g|=       0.50475
## At iterate    50  f =      -1365.8  |proj g|=        3.3505
## At iterate    60  f =      -1367.6  |proj g|=       0.32443
## At iterate    70  f =      -1367.8  |proj g|=       0.40673
## At iterate    80  f =      -1367.8  |proj g|=      0.024166
## 
## iterations 84
## function evaluations 112
## segments explored during Cauchy searches 87
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0432809
## final function value -1367.81
## 
## F = -1367.81
## l(0) > u(0).  No feasible solutionfinal  value -1367.807825 
## converged
## 
## 
## ***************************
## Estimation of CV-set 5/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1379.3  |proj g|=       8.2252
## At iterate    10  f =      -1379.9  |proj g|=       0.25997
## 
## iterations 19
## function evaluations 21
## segments explored during Cauchy searches 19
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0163048
## final function value -1379.93
## 
## F = -1379.93
## final  value -1379.928494 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1138.4  |proj g|=           10
## At iterate    10  f =      -1313.1  |proj g|=        9.6375
## At iterate    20  f =      -1360.7  |proj g|=        20.632
## At iterate    30  f =      -1378.7  |proj g|=        1.3845
## At iterate    40  f =      -1379.3  |proj g|=       0.64874
## At iterate    50  f =      -1379.9  |proj g|=       0.41148
## 
## iterations 52
## function evaluations 82
## segments explored during Cauchy searches 55
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0822048
## final function value -1379.92
## 
## F = -1379.92
## final  value -1379.921269 
## converged
## 
## 
## ***************************
## Estimation of CV-set 6/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1414.4  |proj g|=       5.6919
## At iterate    10  f =      -1414.6  |proj g|=        0.1573
## 
## iterations 16
## function evaluations 18
## segments explored during Cauchy searches 16
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00167618
## final function value -1414.56
## 
## F = -1414.56
## final  value -1414.563094 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1168.5  |proj g|=           10
## At iterate    10  f =      -1371.3  |proj g|=        9.6691
## At iterate    20  f =        -1413  |proj g|=        1.8616
## At iterate    30  f =      -1414.2  |proj g|=       0.49266
## At iterate    40  f =      -1414.4  |proj g|=       0.08069
## At iterate    50  f =      -1414.5  |proj g|=       0.24958
## At iterate    60  f =      -1414.6  |proj g|=        0.3734
## At iterate    70  f =      -1414.6  |proj g|=      0.028823
## 
## iterations 71
## function evaluations 80
## segments explored during Cauchy searches 74
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.019323
## final function value -1414.56
## 
## F = -1414.56
## final  value -1414.563437 
## converged
## 
## 
## ***************************
## Estimation of CV-set 7/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1405.3  |proj g|=       4.6269
## At iterate    10  f =      -1405.9  |proj g|=      0.075784
## 
## iterations 15
## function evaluations 18
## segments explored during Cauchy searches 15
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0120191
## final function value -1405.87
## 
## F = -1405.87
## final  value -1405.871039 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1161.2  |proj g|=           10
## At iterate    10  f =      -1345.2  |proj g|=        4.5939
## At iterate    20  f =      -1391.1  |proj g|=          13.6
## At iterate    30  f =      -1405.2  |proj g|=        2.8239
## At iterate    40  f =      -1405.7  |proj g|=       0.14802
## At iterate    50  f =      -1405.8  |proj g|=          1.24
## At iterate    60  f =      -1405.9  |proj g|=      0.030553
## At iterate    70  f =      -1405.9  |proj g|=       0.12371
## At iterate    80  f =      -1405.9  |proj g|=      0.010473
## 
## iterations 82
## function evaluations 104
## segments explored during Cauchy searches 85
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00739873
## final function value -1405.87
## 
## F = -1405.87
## final  value -1405.870996 
## converged
## 
## 
## ***************************
## Estimation of CV-set 8/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1400.6  |proj g|=       2.9338
## At iterate    10  f =      -1400.7  |proj g|=      0.090315
## 
## iterations 17
## function evaluations 32
## segments explored during Cauchy searches 17
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.0021013
## final function value -1400.68
## 
## F = -1400.68
## l(0) > u(0).  No feasible solutionfinal  value -1400.683009 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1149.6  |proj g|=           10
## At iterate    10  f =        -1319  |proj g|=        9.5623
## At iterate    20  f =      -1387.1  |proj g|=        1.9481
## ys=-6.792e-01  -gs= 1.679e+00, BFGS update SKIPPED
## At iterate    30  f =      -1399.5  |proj g|=        0.8814
## At iterate    40  f =      -1400.4  |proj g|=        1.7275
## At iterate    50  f =      -1400.5  |proj g|=       0.21834
## At iterate    60  f =      -1400.6  |proj g|=       0.40104
## At iterate    70  f =      -1400.7  |proj g|=      0.099121
## 
## iterations 79
## function evaluations 96
## segments explored during Cauchy searches 82
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00211975
## final function value -1400.68
## 
## F = -1400.68
## final  value -1400.682764 
## converged
## 
## 
## ***************************
## Estimation of CV-set 9/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1403.1  |proj g|=        4.845
## At iterate    10  f =      -1403.3  |proj g|=       0.25628
## At iterate    20  f =      -1403.3  |proj g|=     0.0071765
## 
## iterations 20
## function evaluations 24
## segments explored during Cauchy searches 20
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00717647
## final function value -1403.26
## 
## F = -1403.26
## final  value -1403.260850 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1156.9  |proj g|=           10
## ys=-1.465e+01  -gs= 1.667e+01, BFGS update SKIPPED
## At iterate    10  f =      -1325.8  |proj g|=        10.956
## At iterate    20  f =      -1401.6  |proj g|=        2.3066
## At iterate    30  f =      -1402.9  |proj g|=       0.59585
## At iterate    40  f =      -1403.2  |proj g|=        0.7083
## At iterate    50  f =      -1403.2  |proj g|=       0.18873
## At iterate    60  f =      -1403.3  |proj g|=       0.17483
## At iterate    70  f =      -1403.3  |proj g|=      0.022584
## 
## iterations 72
## function evaluations 94
## segments explored during Cauchy searches 75
## BFGS updates skipped 1
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.00951482
## final function value -1403.26
## 
## F = -1403.26
## final  value -1403.260762 
## converged
## 
## 
## ***************************
## Estimation of CV-set 10/10
## Optimisation using starting value 1/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 2 variables are exactly at the bounds
## At iterate     0  f=      -1391.3  |proj g|=       1.0981
## At iterate    10  f =        -1392  |proj g|=        1.5805
## 
## iterations 14
## function evaluations 18
## segments explored during Cauchy searches 14
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 2
## norm of the final projected gradient 0.00690403
## final function value -1392.08
## 
## F = -1392.08
## final  value -1392.076329 
## converged
## 
## Optimisation using starting value 2/2
## N = 10, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1147.2  |proj g|=           10
## At iterate    10  f =      -1295.5  |proj g|=        17.461
## At iterate    20  f =        -1356  |proj g|=        9.7724
## At iterate    30  f =      -1376.4  |proj g|=        5.8376
## At iterate    40  f =      -1390.1  |proj g|=        1.0333
## At iterate    50  f =      -1391.9  |proj g|=       0.87468
## At iterate    60  f =        -1392  |proj g|=       0.24932
## At iterate    70  f =      -1392.1  |proj g|=      0.032837
## 
## iterations 72
## function evaluations 103
## segments explored during Cauchy searches 75
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0563566
## final function value -1392.07
## 
## F = -1392.07
## l(0) > u(0).  No feasible solutionfinal  value -1392.068715 
## converged
## 
print(est.denver.4.4.cv)
## Cross-validation parameter estimation for STmodel
##   with 10 CV-groups and 2 starting points.
##   Results: 1 converged, 9 not converged.
## 
## No fixed parameters.
## 
## Estimated function values and convergence info:
##       value convergence  conv       eigen.min eigen.all.min
## 1  1393.438        TRUE FALSE -0.000073852318            NA
## 2  1399.761        TRUE FALSE -0.000034510592            NA
## 3  1403.814        TRUE FALSE -0.000004488666            NA
## 4  1367.808        TRUE FALSE -0.000162001024            NA
## 5  1379.928        TRUE FALSE -0.000026643061            NA
## 6  1414.563        TRUE FALSE -0.000410279969            NA
## 7  1405.871        TRUE  TRUE  0.000048871308            NA
## 8  1400.683        TRUE FALSE -0.000072151409            NA
## 9  1403.261        TRUE FALSE -0.000122054537            NA
## 10 1392.076        TRUE FALSE -0.000116827437            NA
par(mfrow=c(1,1), mar=c(13.5,2.5,.5,.5), las=2)
with(coef(est.denver.model.4.4, pars="all"),
     plotCI((1:length(par))+.3, par, uiw=1.96*sd,
            col=2, xlab="", xaxt="n", ylab=""))
boxplot(est.denver.4.4.cv, "all", boxwex=.4, col="grey", add=TRUE)

#' Save the results as an .rdata object
save(denver.data4.2, denver.model.4.4, est.denver.model.4.4, est.denver.4.4.cv,
     file = here::here("Results", "Denver_ST_Model_4.4.rdata"))

9.5.4 Prediction using the CV model

Making predictions using the CV model. Printing out the CV summary statistics as well

pred.4.4.cv <- predictCV(denver.model.4.4, est.denver.4.4.cv, LTA = T)
pred.4.4.cv.log <- predictCV(denver.model.4.4, est.denver.4.4.cv,
                             LTA = T, transform="unbiased")

names(pred.4.4.cv)
## [1] "opts"     "Ind.cv"   "pred.obs" "pred.LTA" "pred.all"
summary(pred.4.4.cv)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX
## obs     0.11353932 0.11531514 0.09442065
## average 0.07136323 0.07325164 0.06462387
## 
## R2:
##             EX.mu EX.mu.beta        EX
## obs     0.6964351  0.6868650 0.7900611
## average 0.7769478  0.7649868 0.8170875
## 
## Coverage of 95% prediction intervals:
##                EX
## obs     0.9124797
## average 0.9000000
summary(pred.4.4.cv.log)
## Cross-validation predictions for STmodel with 10 CV-groups.
##   Predictions for 617 observations.
##   Temporal averages for 60 locations.
## 
## RMSE:
##              EX.mu EX.mu.beta         EX    EX.pred
## obs     0.13682618 0.13882065 0.10870333 0.10887138
## average 0.08205341 0.08402903 0.07205214 0.07241891
## 
## R2:
##             EX.mu EX.mu.beta        EX  EX.pred
## obs     0.7101107  0.7015979 0.8170302 0.816464
## average 0.8188451  0.8100167 0.8603147 0.858889
## 
## Coverage of 95% prediction intervals:
##           EX.pred
## obs     0.9124797
## average 0.9166667
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.4.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.4.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")

jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod4.4.jpeg"),
     width = 8, height = 4, units = "in", res = 500)
par(mfrow=c(1,2), mar=c(3.3,3.3,1.5,1), mgp=c(2,1,0))
plot(pred.4.4.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
     col=c("ID", "black", "grey"),
     ylim=c(-1,2),
     xlab="Observations", ylab="Predictions",
     main="Cross-validation BC (log ug/m3)")
with(pred.4.4.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
                                      xlab="Observations", ylab="Predictions",
                                      main="Temporal average BC (ug/m3)"))
abline(0, 1, col="grey")
dev.off()
## png 
##   2

9.6 Model 4.5: Smoothing for beta fields and error term

9.6.1 Create the model object (exp covariance structure)

Now I’m using the exp covariance structure for cov.beta and cov.nu.

names(denver.data4.2$covars)
##  [1] "ID"                  "lon"                 "lat"                
##  [4] "impervious_2500"     "open_2500"           "low_int_100"        
##  [7] "med_int_50"          "high_int_50"         "high_int_100"       
## [10] "ag_250"              "pop_den_50"          "dist_m_compost"     
## [13] "dist_m_military"     "len_m_highways_2500" "aadt_100"           
## [16] "aadt_2500"           "x"                   "y"                  
## [19] "type"
LUR4.5<- list(covar_fun, covar_fun, covar_fun)

cov.beta4.5 <-  list(covf=c("exp", "exp", "exp"), nugget = c(TRUE, TRUE, TRUE))
cov.nu4.5 <- list(covf="exp", nugget = T, random.effect = FALSE)
locations4.5 <- list(coords = c("x","y"), long.lat = c("lon","lat"), others= "type")

denver.model.4.5 <- createSTmodel(denver.data4.2, LUR = LUR4.5,
                                  ST = c("bc_st_no2", "bc_st_smk"),
                                  cov.beta = cov.beta4.5, cov.nu = cov.nu4.5,
                                  locations = locations4.5)
## No trend $trend.fnc object detected, STdata probably from old version of the package.
## $trend.fnc has been added based on spline fit to elements in STmodel$trend.
denver.model.4.5
## STmodel-object with:
##  No. locations: 61 (observed: 61)
##  No. time points: 531 (observed: 155)
##  No. obs: 772
## 
## Trend with 2 basis function(s):
## [1] "V1" "V2"
## with dates:
##  2008-12-29 to 2019-03-11
## 
## Models for the beta-fields are:
## $const
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V1
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## $V2
## ~~impervious_2500 + open_2500 + low_int_100 + med_int_50 + high_int_50 + 
##     high_int_100 + ag_250 + pop_den_50 + dist_m_compost + dist_m_military + 
##     len_m_highways_2500 + aadt_100 + aadt_2500
## 
## 2 spatio-temporal covariate(s):
## [1] "bc_st_no2" "bc_st_smk"
## 
## Covariance model for the beta-field(s):
##  Covariance type(s): exp, exp, exp 
##  Nugget: Yes, Yes, Yes 
## Covariance model for the nu-field(s):
##  Covariance type: exp 
##  Nugget: ~1 
##  Random effect: No 
## All sites:
## central    dist 
##       1      60 
## Observed:
## central    dist 
##       1      60 
## 
## For central:
##   Number of obs: 155
##   Dates: 2016-02-08 to 2019-02-25
## For dist:
##   Number of obs: 617
##   Dates: 2018-05-07 to 2018-11-12

9.6.2 Estimate model parameters

  • nugget values can range from -1 to -6
  • range values can range from 0 to 4
  • try starting values where the sill and nugget are the same (e.g., both 0) and where they are very different (e.g., 0 and -5)
  • make sure the starting values are pretty different
names <- loglikeSTnames(denver.model.4.5, all=FALSE)
names
##  [1] "log.range.const.exp"           "log.sill.const.exp"           
##  [3] "log.nugget.const.exp"          "log.range.V1.exp"             
##  [5] "log.sill.V1.exp"               "log.nugget.V1.exp"            
##  [7] "log.range.V2.exp"              "log.sill.V2.exp"              
##  [9] "log.nugget.V2.exp"             "nu.log.range.exp"             
## [11] "nu.log.sill.exp"               "nu.log.nugget.(Intercept).exp"
# x.init.4.5 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
#                     c(0, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, -1),
#                     c(0, -1, -5, 0, -1, -5, 0, -1, -5, 0, -1, -5),
#                     c(0, -5, -1, 0, -5, -1, 0, -1, -1, 0, -1, -1),
#                     c(0, -5, -5, 0, -5, -5, 0, -1, -5, 0, -1, -5),
#                     c(2, -1, -1, 2, -1, -1, 2, -1, -1, 2, -1, -1),
#                     c(2, -1, -5, 2, -1, -5, 2, -1, -5, 2, -1, -5),
#                     c(2, -5, -1, 2, -5, -1, 2, -1, -1, 2, -1, -1),
#                     c(2, -5, -5, 2, -5, -5, 2, -1, -5, 2, -1, -5),
#                     c(4, -1, -1, 4, -1, -1, 4, -1, -1, 4, -1, -1),
#                     c(4, -1, -5, 4, -1, -5, 4, -1, -5, 4, -1, -5),
#                     c(4, -5, -1, 4, -5, -1, 4, -1, -1, 4, -1, -1),
#                     c(4, -5, -5, 4, -5, -5, 4, -1, -5, 4, -1, -5),
#                     c(6, -1, -1, 6, -1, -1, 6, -1, -1, 6, -1, -1),
#                     c(6, -1, -5, 6, -1, -5, 6, -1, -5, 6, -1, -5),
#                     c(6, -5, -1, 6, -5, -1, 6, -1, -1, 6, -1, -1),
#                     c(6, -5, -5, 6, -5, -5, 6, -1, -5, 6, -1, -5)
#                     )

x.init.4.5 <- cbind(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                    c(6, -5, -1, 6, -5, -1, 6, -1, -1, 6, -1, -1),
                    c(6, -5, -5, 6, -5, -5, 6, -5, -10, 10, -5, -5),
                    c(6, -10, -10, 6, -10, -10, 6, -10, -10, 6, -10, -1),
                    c(6, -10, -5, 6, -10, -5, 6, -5, -5, 6, -5, -5))

rownames(x.init.4.5) <- loglikeSTnames(denver.model.4.5, all=FALSE)
x.init.4.5
##                               [,1] [,2] [,3] [,4] [,5]
## log.range.const.exp              0    6    6    6    6
## log.sill.const.exp               0   -5   -5  -10  -10
## log.nugget.const.exp             0   -1   -5  -10   -5
## log.range.V1.exp                 0    6    6    6    6
## log.sill.V1.exp                  0   -5   -5  -10  -10
## log.nugget.V1.exp                0   -1   -5  -10   -5
## log.range.V2.exp                 0    6    6    6    6
## log.sill.V2.exp                  0   -1   -5  -10   -5
## log.nugget.V2.exp                0   -1  -10  -10   -5
## nu.log.range.exp                 0    6   10    6    6
## nu.log.sill.exp                  0   -1   -5  -10   -5
## nu.log.nugget.(Intercept).exp    0   -1   -5   -1   -5
#' Difference from tutorial: use Josh Keller's version of the function
source(here::here("Code", "functions_model.R"))
est.denver.model.4.5 <- estimate.STmodel(denver.model.4.5, x.init.4.5)
## Optimisation using starting value 1/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=        405.3  |proj g|=           15
## At iterate    10  f =        -1342  |proj g|=       0.31682
## At iterate    20  f =      -1343.1  |proj g|=        1.2303
## 
## iterations 25
## function evaluations 34
## segments explored during Cauchy searches 27
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.26398
## final function value -1343.16
## 
## F = -1343.16
## final  value -1343.159535 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 2/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      0.14687  |proj g|=           14
## At iterate    10  f =      -1465.2  |proj g|=        13.888
## At iterate    20  f =      -1514.9  |proj g|=       0.46872
## At iterate    30  f =      -1515.6  |proj g|=       0.91357
## At iterate    40  f =      -1529.6  |proj g|=        6.3209
## At iterate    50  f =      -1530.2  |proj g|=        2.3435
## At iterate    60  f =      -1530.2  |proj g|=      0.022824
## 
## iterations 66
## function evaluations 84
## segments explored during Cauchy searches 70
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0797041
## final function value -1530.22
## 
## F = -1530.22
## final  value -1530.215805 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
## Optimisation using starting value 3/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1347.4  |proj g|=           10
## At iterate    10  f =      -1525.7  |proj g|=        5.0629
## At iterate    20  f =      -1530.7  |proj g|=        1.9114
## At iterate    30  f =        -1531  |proj g|=       0.66668
## At iterate    40  f =      -1531.1  |proj g|=       0.42689
## At iterate    50  f =      -1531.1  |proj g|=      0.099497
## At iterate    60  f =      -1531.2  |proj g|=       0.36816
## At iterate    70  f =      -1531.2  |proj g|=      0.033172
## 
## iterations 70
## function evaluations 90
## segments explored during Cauchy searches 72
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 4
## norm of the final projected gradient 0.0331722
## final function value -1531.16
## 
## F = -1531.16
## l(0) > u(0).  No feasible solutionfinal  value -1531.158199 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 4/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -373.68  |proj g|=           14
## At iterate    10  f =        -1342  |proj g|=        11.034
## At iterate    20  f =      -1343.1  |proj g|=        1.3831
## At iterate    30  f =        -1363  |proj g|=        11.814
## At iterate    40  f =      -1507.7  |proj g|=        4.7123
## At iterate    50  f =      -1514.2  |proj g|=      0.070596
## At iterate    60  f =      -1514.4  |proj g|=        1.2429
## At iterate    70  f =        -1530  |proj g|=        6.4415
## At iterate    80  f =      -1530.7  |proj g|=        6.6962
## 
## iterations 89
## function evaluations 118
## segments explored during Cauchy searches 91
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 1
## norm of the final projected gradient 0.023767
## final function value -1531.15
## 
## F = -1531.15
## final  value -1531.149663 
## converged
## Warning in sqrt(-diag(tryCatch(solve(res[[i]]$hessian), error = function(e)
## rep(-10000, : NaNs produced
## Optimisation using starting value 5/5
## N = 12, M = 5 machine precision = 2.22045e-16
## At X0, 0 variables are exactly at the bounds
## At iterate     0  f=      -1269.2  |proj g|=           10
## At iterate    10  f =        -1476  |proj g|=        6.0854
## At iterate    20  f =      -1516.5  |proj g|=        1.0259
## At iterate    30  f =        -1530  |proj g|=       0.56463
## At iterate    40  f =      -1530.2  |proj g|=       0.14071
## At iterate    50  f =      -1530.2  |proj g|=       0.45046
## At iterate    60  f =      -1530.2  |proj g|=      0.034901
## 
## iterations 60
## function evaluations 80
## segments explored during Cauchy searches 64
## BFGS updates skipped 0
## active bounds at final generalized Cauchy point 3
## norm of the final projected gradient 0.0349012
## final function value -1530.22
## 
## F = -1530.22
## final  value -1530.215995 
## converged
## Warning in res[[i]][[par.type]]$sd[is.na(x.fixed)] <- par.sd: number of items to
## replace is not a multiple of replacement length
print(est.denver.model.4.5)
## Optimisation for STmodel with 5 starting points.
##   Results: 0 converged, 5 not converged, 0 failed.
##   Best result for starting point 3, optimisation has NOT converged
## 
## No fixed parameters.
## 
## Estimated parameters for all starting point(s):
##                                            [,1]            [,2]           [,3]
## gamma.bc_st_no2                   0.01350078733   0.01841300070   0.0185086935
## gamma.bc_st_smk                   0.07846978210   0.05694253014   0.0544493083
## alpha.const.(Intercept)           0.06595054905  -0.00460283714  -0.0096803423
## alpha.const.impervious_2500       0.05712444032   0.06497141354   0.0650464097
## alpha.const.open_2500             0.02006127944   0.02916028758   0.0291973832
## alpha.const.low_int_100           0.00941997870   0.02074075392   0.0208623836
## alpha.const.med_int_50            0.00460016667  -0.00555174873  -0.0054983350
## alpha.const.high_int_50           0.01786609573   0.00548192326   0.0058525650
## alpha.const.high_int_100         -0.02377008994   0.00006185841  -0.0003935041
## alpha.const.ag_250               -0.00332233386  -0.00129705434  -0.0013567770
## alpha.const.pop_den_50            0.00325333059   0.00256192733   0.0023638630
## alpha.const.dist_m_compost        0.00555491102   0.00040677448   0.0002908794
## alpha.const.dist_m_military       0.01970557029   0.00659122823   0.0063835456
## alpha.const.len_m_highways_2500   0.00101506480   0.00541419248   0.0052464941
## alpha.const.aadt_100              0.03724246211   0.02157871918   0.0223682562
## alpha.const.aadt_2500            -0.00040492038  -0.01019814485  -0.0101726352
## alpha.V1.(Intercept)             -0.28068517626  -0.29086698491  -0.2913507424
## alpha.V1.impervious_2500         -0.05827941156  -0.05862737003  -0.0569798432
## alpha.V1.open_2500               -0.04249471710  -0.03937033732  -0.0382750034
## alpha.V1.low_int_100              0.00007194597  -0.00814194074  -0.0075365816
## alpha.V1.med_int_50              -0.00455989441  -0.00534989972  -0.0046998958
## alpha.V1.high_int_50              0.00947037990  -0.00326603058  -0.0004063456
## alpha.V1.high_int_100            -0.03376006461  -0.00891483117  -0.0128365920
## alpha.V1.ag_250                  -0.00861851822   0.01343303992   0.0130141485
## alpha.V1.pop_den_50              -0.01315608528  -0.00086699274  -0.0026430249
## alpha.V1.dist_m_compost          -0.02444252029  -0.00336530800  -0.0043803440
## alpha.V1.dist_m_military         -0.01274992086   0.00894896339   0.0077492006
## alpha.V1.len_m_highways_2500      0.00674918765   0.01292800182   0.0122458979
## alpha.V1.aadt_100                 0.01538592245   0.01137115083   0.0182216017
## alpha.V1.aadt_2500                0.00816928865   0.01408569976   0.0142291162
## alpha.V2.(Intercept)             -0.12742397145  -0.09305199034  -0.1036985031
## alpha.V2.impervious_2500         -0.01901972919  -0.00502779599  -0.0032017298
## alpha.V2.open_2500                0.00929692321   0.02030217154   0.0217297218
## alpha.V2.low_int_100              0.00420900765   0.00431490868   0.0052973161
## alpha.V2.med_int_50              -0.00473677346  -0.01517129684  -0.0145585623
## alpha.V2.high_int_50             -0.00778474494  -0.03412775747  -0.0306324468
## alpha.V2.high_int_100            -0.03734156313   0.01840200242   0.0140358066
## alpha.V2.ag_250                  -0.02637657116  -0.00234169930  -0.0027021353
## alpha.V2.pop_den_50               0.00307907496   0.00897419427   0.0070920546
## alpha.V2.dist_m_compost           0.00611788947   0.02759897142   0.0263774046
## alpha.V2.dist_m_military          0.01212393703   0.02889767640   0.0274407383
## alpha.V2.len_m_highways_2500      0.01441054837   0.02376772963   0.0227284233
## alpha.V2.aadt_100                 0.00147564231  -0.02484043139  -0.0177173495
## alpha.V2.aadt_2500                0.00039285089  -0.00115242485  -0.0009381536
## log.range.const.exp               0.00000000000   6.78638948501   6.1396812447
## log.sill.const.exp              -14.78545135167 -15.00000000000 -15.0000000000
## log.nugget.const.exp            -15.00000000000 -15.00000000000 -15.0000000000
## log.range.V1.exp                  0.00000000000  -0.64987761551   3.3293440224
## log.sill.V1.exp                 -10.80141273552  -6.62433468969 -15.0000000000
## log.nugget.V1.exp                -8.70161475379 -14.52365130439  -6.6094142075
## log.range.V2.exp                  0.00000000000   6.40319515566   6.4041753523
## log.sill.V2.exp                  -9.98069768419  -6.21408656155  -6.0450760907
## log.nugget.V2.exp                -7.38861930690  -7.86612705202 -14.9822056492
## nu.log.range.exp                  0.00000000000  15.00000000000  15.0000000000
## nu.log.sill.exp                  -7.69956639778  -3.80310298308  -3.8072270482
## nu.log.nugget.(Intercept).exp    -4.56525483344  -5.67653913443  -5.6798853040
##                                           [,4]            [,5]
## gamma.bc_st_no2                   0.0185102792   0.01841239180
## gamma.bc_st_smk                   0.0544411610   0.05695493120
## alpha.const.(Intercept)          -0.0097147928  -0.00458605546
## alpha.const.impervious_2500       0.0650448162   0.06497377671
## alpha.const.open_2500             0.0291965930   0.02916282982
## alpha.const.low_int_100           0.0208634665   0.02074059703
## alpha.const.med_int_50           -0.0055006427  -0.00554965920
## alpha.const.high_int_50           0.0058534438   0.00548007281
## alpha.const.high_int_100         -0.0003930292   0.00006320603
## alpha.const.ag_250               -0.0013548750  -0.00129647554
## alpha.const.pop_den_50            0.0023666883   0.00256127491
## alpha.const.dist_m_compost        0.0002911471   0.00040820269
## alpha.const.dist_m_military       0.0063832041   0.00659233516
## alpha.const.len_m_highways_2500   0.0052451109   0.00541528018
## alpha.const.aadt_100              0.0223676861   0.02157816480
## alpha.const.aadt_2500            -0.0101710034  -0.01019994927
## alpha.V1.(Intercept)             -0.2913494666  -0.29085217266
## alpha.V1.impervious_2500         -0.0569909039  -0.05861356322
## alpha.V1.open_2500               -0.0382751320  -0.03936101307
## alpha.V1.low_int_100             -0.0075312225  -0.00814456846
## alpha.V1.med_int_50              -0.0047078692  -0.00534479831
## alpha.V1.high_int_50             -0.0004186290  -0.00326696866
## alpha.V1.high_int_100            -0.0128072593  -0.00892161904
## alpha.V1.ag_250                   0.0130271042   0.01343507641
## alpha.V1.pop_den_50              -0.0026343238  -0.00086510437
## alpha.V1.dist_m_compost          -0.0043759918  -0.00335713102
## alpha.V1.dist_m_military          0.0077482194   0.00895724386
## alpha.V1.len_m_highways_2500      0.0122530142   0.01292574023
## alpha.V1.aadt_100                 0.0182113697   0.01136797562
## alpha.V1.aadt_2500                0.0142273844   0.01408710991
## alpha.V2.(Intercept)             -0.1037265756  -0.09299193688
## alpha.V2.impervious_2500         -0.0032095974  -0.00501726500
## alpha.V2.open_2500                0.0217358675   0.02030795686
## alpha.V2.low_int_100              0.0053118141   0.00430758132
## alpha.V2.med_int_50              -0.0145689228  -0.01516570310
## alpha.V2.high_int_50             -0.0306508674  -0.03412951997
## alpha.V2.high_int_100             0.0140778503   0.01839135781
## alpha.V2.ag_250                  -0.0026821930  -0.00234355248
## alpha.V2.pop_den_50               0.0071024509   0.00897877016
## alpha.V2.dist_m_compost           0.0263826968   0.02760912927
## alpha.V2.dist_m_military          0.0274417993   0.02890407374
## alpha.V2.len_m_highways_2500      0.0227314220   0.02376962157
## alpha.V2.aadt_100                -0.0177334987  -0.02483942526
## alpha.V2.aadt_2500               -0.0009302915  -0.00115830941
## log.range.const.exp               6.0854639765   6.35284809357
## log.sill.const.exp              -14.8354752257 -15.00000000000
## log.nugget.const.exp            -14.8361484349 -15.00000000000
## log.range.V1.exp                  5.3265411356   1.87797258060
## log.sill.V1.exp                 -13.4974003348  -6.62477257880
## log.nugget.V1.exp                -6.6082690301 -14.15820843321
## log.range.V2.exp                  6.4096640958   6.40001276023
## log.sill.V2.exp                  -6.0463363268  -6.21628586352
## log.nugget.V2.exp               -11.6840633145  -7.87573188976
## nu.log.range.exp                 15.0000000000  15.00000000000
## nu.log.sill.exp                  -3.8075122852  -3.80305967182
## nu.log.nugget.(Intercept).exp    -5.6802420409  -5.67658082894
## 
## Function value(s):
## [1] 1343.160 1530.216 1531.158 1531.150 1530.216

9.6.3 Cross-validation

Define the CV groups

set.seed(123)

unique(colnames(bc_obs2))
##  [1] "d_2"     "d_4"     "d_6"     "d_8"     "d_16"    "d_18"    "d_20"   
##  [8] "d_12"    "d_14"    "d_22"    "d_24"    "d_26"    "d_5"     "d_7"    
## [15] "d_15"    "d_17"    "d_19"    "d_11"    "d_13"    "d_21"    "d_23"   
## [22] "d_25"    "d_28"    "d_30"    "d_32"    "d_40"    "d_41"    "d_42"   
## [29] "d_10"    "d_34"    "d_36"    "d_38"    "d_43"    "d_44"    "d_45"   
## [36] "d_3"     "d_1"     "d_27"    "d_29"    "d_31"    "d_39"    "d_9"    
## [43] "d_33"    "d_35"    "d_37"    "d_49"    "d_51"    "d_55"    "d_52"   
## [50] "d_56"    "d_50"    "d_54"    "d_46"    "d_47"    "d_53"    "d_48"   
## [57] "d_58"    "d_59"    "d_60"    "d_57"    "central"
Ind.cv.4.5 <- createCV(denver.model.4.5, groups = 10, #min.dist = .1,
                       subset = paste0("d_", c(1:60)))

ID.cv.4.5 <- sapply(split(denver.model.4.5$obs$ID, Ind.cv.4.5), unique)
print(sapply(ID.cv.4.5, length))
##  0  1  2  3  4  5  6  7  8  9 10 
##  1  6  6  6  6  6  6  6  6  6  6
table(Ind.cv.4.5)
## Ind.cv.4.5
##   0   1   2   3   4   5   6   7   8   9  10 
## 155  65  61  59  75  67  51  57  62  56  64
I.col.4.5 <- apply(sapply(ID.cv.4.5,function(x) denver.model.4.5$locations$ID%in% x), 1,
                   function(x) if(sum(x)==1) which(x) else 0)
names(I.col.4.5) <- denver.model.4.5$locations$ID
print(I.col.4.5)
## central     d_2     d_4     d_6    d_12    d_14    d_16    d_18    d_20    d_22 
##       1       6       9      11       4      11       2       8      11       9 
##    d_24    d_26     d_5     d_7     d_8    d_11    d_13    d_15    d_17    d_19 
##       7       2       9      10       2      10      11       6      11       6 
##    d_21    d_23    d_25     d_3    d_10    d_28    d_30    d_32    d_34    d_36 
##      10       3       3       8       8       3       5      10       5       4 
##    d_38    d_40    d_41    d_42    d_43    d_44    d_45     d_1     d_9    d_27 
##       5       4       7       2       7       8       6       2       5       5 
##    d_29    d_31    d_33    d_37    d_39    d_35    d_49    d_51    d_52    d_55 
##       4       7       5       9       4       3       6       8      11       4 
##    d_56    d_46    d_47    d_50    d_53    d_54    d_48    d_58    d_59    d_60 
##       9       9       8      10       2       6       3       3       7       7 
##    d_57 
##      10
par(mfrow=c(1,1))
plot(denver.model.4.5$locations$long,
     denver.model.4.5$locations$lat,
     pch=23+floor(I.col.4.5/max(I.col.4.5)+.5), bg=I.col.4.5,
     xlab="Longitude", ylab="Latitude")

map("county", "colorado", col="#FFFF0055",fill=TRUE, add=TRUE)
## [[1]]
## NULL

ID starting conditions using previous model without CV:

x.init.4.5.cv <- coef(est.denver.model.4.5, pars="cov")[,c("par","init")]
x.init.4.5.cv

Run the model with cross validation.

When I ran the CV model I got the following error for the 5th CV set

Error in solve.default(res[[i]]$hessian) : system is computationally singular: reciprocal condition number = 3.3547e-17

# est.denver.4.5.cv <- estimateCV(denver.model.4.5, x.init.4.5.cv, Ind.cv.4.5)
# print(est.denver.4.5.cv)
# 
# par(mfrow=c(1,1), mar=c(13.5,4.5,.5,.5), las=2)
# with(coef(est.denver.model.4.5, pars="all"),
#      plotCI((1:length(par))+.3, par, uiw=1.96*sd,
#             col=2, xlab="", xaxt="n", ylab=""))
# boxplot(est.denver.4.5.cv, "all", boxwex=.4, col="grey", add=TRUE)
# 
# #' Save the results as an .rdata object
# save(denver.data4.2, denver.model.4.5, est.denver.model.4.5, est.denver.4.5.cv,
#      file = here::here("Results", "Denver_ST_Model_4.5.rdata"))

9.6.4 Prediction using the CV model

I didn’t make predictions with the CV model since it wasn’t successfully implemented

# pred.4.5.cv <- predictCV(denver.model.4.5, est.denver.4.5.cv, LTA = T)
# pred.4.5.cv.log <- predictCV(denver.model.4.5, est.denver.4.5.cv,
#                              LTA = T, transform="unbiased")
# 
# names(pred.4.5.cv)
# summary(pred.4.5.cv)
# summary(pred.4.5.cv.log)
# 
# par(mfrow=c(1,2), mar=c(3.3,3.3,4.5,1), mgp=c(2,1,0))
# plot(pred.4.5.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
#      col=c("ID", "black", "grey"),
#      ylim=c(-1,2),
#      xlab="Observations", ylab="Predictions",
#      main="Cross-validation BC (log ug/m3)")
# with(pred.4.5.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
#                                       xlab="Observations", ylab="Predictions",
#                                       main="Temporal average BC (ug/m3)"))
# abline(0, 1, col="grey")
# 
# jpeg(filename = here::here("Figs", "ST_CV_Obs_vs_Pred_BC_Mod4.5.jpeg"),
#      width = 8, height = 4, units = "in", res = 500)
# par(mfrow=c(1,2), mar=c(3.3,3.3,4.5,1), mgp=c(2,1,0))
# plot(pred.4.5.cv, "obs", ID="all", pch=c(19,NA), cex=.25, lty=c(NA,2),
#      col=c("ID", "black", "grey"),
#      ylim=c(-1,2),
#      xlab="Observations", ylab="Predictions",
#      main="Cross-validation BC (log ug/m3)")
# with(pred.4.5.cv.log$pred.LTA, plotCI(obs, EX.pred, uiw=1.96*sqrt(VX.pred),
#                                       xlab="Observations", ylab="Predictions",
#                                       main="Temporal average BC (ug/m3)"))
# abline(0, 1, col="grey")
# dev.off()

10 Summary Table

Summary of model diagnostics
model trend_data trend_start trend_end ST_vars cov_beta0 cov_beta1 cov_beta2 cov_nu_error no_basis_fns df_per_year all_converge all_conv cv_rmse_obs cv_rmse_avg cv_r2_obs cv_r2_avg cv_coverage_obs cv_coverage_avg
Model 1.1 BC 2016 2019 bc_st_no2 iid iid NA iid 1 4 TRUE TRUE 0.13 0.06 0.74 0.89 0.98 0.80
Model 1.2 BC 2016 2019 bc_st_no2 iid iid NA exp 1 4 TRUE TRUE 0.11 0.07 0.82 0.87 0.92 0.87
Model 1.3 BC 2016 2019 bc_st_no2 exp iid NA exp 1 4 TRUE FALSE 0.11 0.07 0.82 0.87 0.92 0.88
Model 1.4 BC 2016 2019 bc_st_no2 iid exp NA exp 1 4 FALSE FALSE 0.11 0.07 0.82 0.88 0.92 0.87
Model 1.5 BC 2016 2019 bc_st_no2 exp exp NA exp 1 4 FALSE FALSE 0.11 0.07 0.82 0.87 0.92 0.87
Model 2.1 NO2 + BC 2009 2019 bc_st_no22 iid iid iid iid 2 4 TRUE FALSE 0.13 0.06 0.75 0.89 0.96 0.82
Model 2.2 NO2 + BC 2009 2019 bc_st_no22 iid iid iid exp 2 4 TRUE TRUE 0.11 0.07 0.82 0.87 0.92 0.93
Model 2.3 NO2 + BC 2009 2019 bc_st_no22 exp iid iid exp 2 4 TRUE FALSE 0.11 0.07 0.82 0.87 0.92 0.93
Model 2.4 NO2 + BC 2009 2019 bc_st_no22 iid exp exp exp 2 4 FALSE FALSE 0.11 0.07 0.82 0.86 0.91 0.92
Model 2.5 NO2 + BC 2009 2019 bc_st_no22 exp exp exp exp 2 4 NA NA NA NA NA NA NA NA
Model 3.1 NO2 + BC 2009 2019 bc_st_no22 iid iid NA iid 1 4 TRUE TRUE 0.29 0.20 0.00 0.00 0.97 0.78
Model 3.2 NO2 + BC 2009 2019 bc_st_no22 iid iid NA exp 1 4 TRUE TRUE 0.10 0.07 0.85 0.89 0.92 0.83
Model 3.3 NO2 + BC 2009 2019 bc_st_no22 exp iid NA exp 1 4 TRUE TRUE 0.10 0.07 0.85 0.89 0.92 0.83
Model 3.4 NO2 + BC 2009 2019 bc_st_no22 iid exp NA exp 1 4 FALSE FALSE 0.10 0.07 0.85 0.88 0.92 0.83
Model 3.5 NO2 + BC 2009 2019 bc_st_no22 exp exp NA exp 1 4 TRUE FALSE 0.10 0.07 0.85 0.89 0.92 0.83
Model 4.1 NO2 + BC 2009 2019 bc_st_no22, bc_st_smk2 iid iid iid iid 2 4 TRUE TRUE 0.12 0.06 0.78 0.90 0.97 0.83
Model 4.2 NO2 + BC 2009 2019 bc_st_no22, bc_st_smk2 iid iid iid exp 2 4 TRUE TRUE 0.11 0.07 0.82 0.87 0.92 0.93
Model 4.3 NO2 + BC 2009 2019 bc_st_no22, bc_st_smk2 exp iid iid exp 2 4 TRUE FALSE 0.11 0.07 0.82 0.87 0.92 0.93
Model 4.4 NO2 + BC 2009 2019 bc_st_no22, bc_st_smk2 iid exp exp exp 2 4 TRUE FALSE 0.11 0.07 0.82 0.86 0.91 0.92
Model 4.5 NO2 + BC 2009 2019 bc_st_no22, bc_st_smk2 exp exp exp exp 2 4 NA NA NA NA NA NA NA NA

11 Additional Notes

11.1 All of Josh Keller’s advice for fitting the intital models

Pasting here for safe keeping

Your sleuthing about that error is correct. A singular hessian matrix (the hessian is a like a matrix analogue of a second derivative) is symptomatic of the optimization algorithm not finding the true minimum. I remember this error all too well! To deal with this, I suggest the following:

  • Use the version of estimate.STmodel() in the attached file instead of the one that is in the package. If you load the package, then source this file, it will overwrite the package function so you can use this version. This version has two changes:

    • It changes the error handling to catch the non-invertible warning and output an obviously wrong value for the standard deviation (-1000). This doesn’t fix the problem at all, but keeps the function from aborting, as the package version does, since the abort makes you lose all of your results that far. This makes it more practical to use multiple starting values in a single function call, since it won’t abort half way through.
    • It uses the function hessian() from the numDeriv package to provide a more numerically-accurate estimate of the Hessian matrix. The package version of the hessian is still stored in the optim_hessian object, while the new version is in the hessian object. This means you’ll need to install the numDeriv package.
  • Try a set of different initial conditions. The numerical algorithm used to maximize the likelihood can get stuck in some areas, so using a set of several initial conditions is a good way to try to ensure that you’re getting the best solution. The package should be able to loop through several initial values and pick the one giving the best result. Let me know if you’d like any suggested values to try.

  • Try a simpler model. I’m not sure exactly what model structure you’re using, but it often helps to start with a smaller model (e.g. 1 time trend, and iid covariance structure) to get a sense of the ranges of the parameters. You can then use the estimates from the simpler model as approximate starting values for a more complicated fit.